﻿using DLLPC.Utilities;
using System.Threading.Tasks;

namespace VisionCore
{
    public class Motion_Exc : ProcedureHelper_Exc
    {
        public void CV1_TrackSW_YRun()
        {
            double acc = 0.5;
            double dec = 0.5;

            #region 位置更新
            Pos_CV1_TrackSW_Y[0] = ParameterHelper.SysParam.CV1_TrackSW_Y.LDPt1;
            Pos_CV1_TrackSW_Y[1] = ParameterHelper.SysParam.CV1_TrackSW_Y.LDPt2;
            Pos_CV1_TrackSW_Y[2] = ParameterHelper.SysParam.CV1_TrackSW_Y.Insp1;
            Pos_CV1_TrackSW_Y[3] = ParameterHelper.SysParam.CV1_TrackSW_Y.Insp2;
            //Pos_CV1_TrackSW_Y[4] = ParameterHelper.SysParam.CV1_TrackSW_Y.Wait;
            #endregion

            CV1_TrackSW_Y_Stop = CV1_TrackSW_Y_ToStop || Kernel.motion.CV1_TrackSW_Y.AxisMotionIO.SVON == 0 || (!CV1_TrackSW_Y_AllowMove && (CV1_TrackSW_Y_RunCode > 0 ));
            CV1_TrackSW_Y_ToStop = false;

            #region Y轴            
            if (CV1_TrackSW_Y_Stop)
            {
                if (Kernel.motion.CV1_TrackSW_Y.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.CV1_TrackSW_Y.Stop();
                }
            }

            if (CV1_TrackSW_Y_HomeCondition)
            {
                if ((ManualMode && CV1_TrackSW_Y_ToHome) || CV1_TrackSW_Y_ToHome_A)
                {
                    CV1_TrackSW_Y_Homing = true;
                }
            }

            if (CV1_TrackSW_Y_MoveCondition )
            {
                if ((ManualMode && CV1_TrackSW_Y_ToLDPt1) || CV1_TrackSW_Y_LDPt1_A) { if(!CV1_TrackSW_Y_LDPt1)  { CV1_TrackSW_Y_RunCode = 1; } }
                if ((ManualMode && CV1_TrackSW_Y_ToLDPt2) || CV1_TrackSW_Y_LDPt2_A) { if (!CV1_TrackSW_Y_LDPt2) { CV1_TrackSW_Y_RunCode = 2; } }
                if ((ManualMode && CV1_TrackSW_Y_ToInsp1) || CV1_TrackSW_Y_ToInsp1_A) { if (!CV1_TrackSW_Y_Insp1) { CV1_TrackSW_Y_RunCode = 3; } }
                if ((ManualMode && CV1_TrackSW_Y_ToInsp2) || CV1_TrackSW_Y_ToInsp2_A) { if (!CV1_TrackSW_Y_Insp2) { CV1_TrackSW_Y_RunCode = 4; } }
               
                CV1_TrackSW_Y_Runing = CV1_TrackSW_Y_RunCode > 0;
            }

            CV1_TrackSW_Y_HomeCondition = Kernel.motion.CV1_TrackSW_Y.AxisMotionIO.ALM == 0 && Kernel.motion.CV1_TrackSW_Y.AxisMotionStatus.Stop == 1 && CV1_TrackSW_Y_RunCode == 0 && !CV1_TrackSW_Y_Homing && !CV1_TrackSW_Y_Stop;
            CV1_TrackSW_Y_MoveCondition = CV1_TrackSW_Y_HomeCondition && Kernel.motion.CV1_TrackSW_Y.IsHomeAlready && Kernel.motion.CV1_TrackSW_Y.AxisMotionStatus.Stop == 1;

            if (CV1_TrackSW_Y_Stop || Kernel.motion.CV1_TrackSW_Y.AxisMotionIO.ALM == 1)
            {
                CV1_TrackSW_Y_RunCode = 0;
            }

            acc = 0.5;
            dec = 0.5;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.TrackSW1_Y_Vel > 1000) ? 1000 : ParameterHelper.SysParam.EQ.Speed.TrackSW1_Y_Vel;
            AxisRun(Kernel.motion.CV1_TrackSW_Y, ref CV1_TrackSW_Y_Runing, CV1_TrackSW_Y_RunCode, Pos_CV1_TrackSW_Y, 1, speed_Y, acc, dec);

            if (CV1_TrackSW_Y_Homing)
            {
                if (!Kernel.motion.CV1_TrackSW_Y.IsHomeAlready)
                {
                    Kernel.motion.CV1_TrackSW_Y.HomeStart = true;
                }
                CV1_TrackSW_Y_Homing = false;
            }

            if (Kernel.motion.CV1_TrackSW_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.CV1_TrackSW_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CV1_TrackSW_Y.IsHomeAlready == true)
            {
                CV1_TrackSW_Y_LDPt1 = Kernel.motion.CheckINP(Kernel.motion.CV1_TrackSW_Y.CurrentActPos, Pos_CV1_TrackSW_Y[0], 0.002);
                CV1_TrackSW_Y_LDPt2 = Kernel.motion.CheckINP(Kernel.motion.CV1_TrackSW_Y.CurrentActPos, Pos_CV1_TrackSW_Y[1], 0.002);
                CV1_TrackSW_Y_Insp1 = Kernel.motion.CheckINP(Kernel.motion.CV1_TrackSW_Y.CurrentActPos, Pos_CV1_TrackSW_Y[2], 0.002);
                CV1_TrackSW_Y_Insp2 = Kernel.motion.CheckINP(Kernel.motion.CV1_TrackSW_Y.CurrentActPos, Pos_CV1_TrackSW_Y[3], 0.002);
                
                if (CV1_TrackSW_Y_LDPt1|| CV1_TrackSW_Y_LDPt2 || CV1_TrackSW_Y_Insp1 || CV1_TrackSW_Y_Insp2)
                {
                    CV1_TrackSW_Y_RunCode = 0;
                }
            }
            else
            {
                CV1_TrackSW_Y_LDPt1 =false;
                CV1_TrackSW_Y_LDPt2 = false;
                CV1_TrackSW_Y_Insp1 = false;
                CV1_TrackSW_Y_Insp2 = false;
            }

            if (Kernel.motion.CV1_TrackSW_Y.AxisMotionIO.SVON == 0 || Kernel.motion.CV1_TrackSW_Y.AxisMotionIO.ALM == 1 )
            {
                Kernel.motion.CV1_TrackSW_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CV1_TrackSW_Y_ToHome= false;
            CV1_TrackSW_Y_ToLDPt1 = false;
            CV1_TrackSW_Y_ToLDPt2 = false;
            CV1_TrackSW_Y_ToInsp1 = false;
            CV1_TrackSW_Y_ToInsp2 = false;
            #endregion

            #region 状态刷新  
            CV1_TrackSW_Y_LDPt1_BL = (PulseOn.Pulse_1s && (CV1_TrackSW_Y_RunCode == 1)) || CV1_TrackSW_Y_LDPt1;
            CV1_TrackSW_Y_LDPt2_BL = (PulseOn.Pulse_1s && (CV1_TrackSW_Y_RunCode == 2)) || CV1_TrackSW_Y_LDPt2;
            CV1_TrackSW_Y_Insp1_BL = (PulseOn.Pulse_1s && (CV1_TrackSW_Y_RunCode == 3)) || CV1_TrackSW_Y_Insp1;
            CV1_TrackSW_Y_Insp2_BL = (PulseOn.Pulse_1s && (CV1_TrackSW_Y_RunCode == 4)) || CV1_TrackSW_Y_Insp2;

            CV1_TrackSW_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CV1_TrackSW_Y.IsHomeAlready;
            #endregion
        }
        public void CV2_TrackSW_YRun()
        {
            double acc = 0.5;
            double dec = 0.5;

            #region 位置更新
            Pos_CV2_TrackSW_Y[0] = ParameterHelper.SysParam.CV2_TrackSW_Y.LDPt1;
            Pos_CV2_TrackSW_Y[1] = ParameterHelper.SysParam.CV2_TrackSW_Y.LDPt2;
            Pos_CV2_TrackSW_Y[2] = ParameterHelper.SysParam.CV2_TrackSW_Y.Insp1;
            Pos_CV2_TrackSW_Y[3] = ParameterHelper.SysParam.CV2_TrackSW_Y.Insp2;
            #endregion

            CV2_TrackSW_Y_Stop = CV2_TrackSW_Y_ToStop || Kernel.motion.CV2_TrackSW_Y.AxisMotionIO.SVON == 0 || (!CV2_TrackSW_Y_AllowMove && (CV2_TrackSW_Y_RunCode > 0));
            CV2_TrackSW_Y_ToStop = false;

            #region           
            if (CV2_TrackSW_Y_Stop)
            {
                if (Kernel.motion.CV2_TrackSW_Y.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.CV2_TrackSW_Y.Stop();
                }
            }

            if (CV2_TrackSW_Y_HomeCondition)
            {
                if ((ManualMode && CV2_TrackSW_Y_ToHome) || CV2_TrackSW_Y_ToHome_A)
                {
                    CV2_TrackSW_Y_Homing = true;
                }
            }
          

            if (CV2_TrackSW_Y_MoveCondition)
            {
                if ((ManualMode && CV2_TrackSW_Y_ToLDPt1) || CV2_TrackSW_Y_LDPt1_A) { if (!CV2_TrackSW_Y_LDPt1) { CV2_TrackSW_Y_RunCode = 1; } }
                if ((ManualMode && CV2_TrackSW_Y_ToLDPt2) || CV2_TrackSW_Y_LDPt2_A) { if (!CV2_TrackSW_Y_LDPt2) { CV2_TrackSW_Y_RunCode = 2; } }
                if ((ManualMode && CV2_TrackSW_Y_ToInsp1) || CV2_TrackSW_Y_ToInsp1_A) { if (!CV2_TrackSW_Y_Insp1) { CV2_TrackSW_Y_RunCode = 3; } }
                if ((ManualMode && CV2_TrackSW_Y_ToInsp2) || CV2_TrackSW_Y_ToInsp2_A) { if (!CV2_TrackSW_Y_Insp2) { CV2_TrackSW_Y_RunCode = 4; } }
               
                CV2_TrackSW_Y_Runing = CV2_TrackSW_Y_RunCode > 0;
            }

            CV2_TrackSW_Y_HomeCondition = Kernel.motion.CV2_TrackSW_Y.AxisMotionIO.ALM == 0 && Kernel.motion.CV2_TrackSW_Y.AxisMotionStatus.Stop == 1 && CV2_TrackSW_Y_RunCode == 0 && !CV2_TrackSW_Y_Homing && !CV2_TrackSW_Y_Stop;
            CV2_TrackSW_Y_MoveCondition = CV2_TrackSW_Y_HomeCondition && Kernel.motion.CV2_TrackSW_Y.IsHomeAlready && Kernel.motion.CV2_TrackSW_Y.AxisMotionStatus.Stop == 1;

            if (CV2_TrackSW_Y_Stop || Kernel.motion.CV2_TrackSW_Y.AxisMotionIO.ALM == 1)
            {
                CV2_TrackSW_Y_RunCode = 0;
            }

            acc = 0.5;
            dec = 0.5;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.TrackSW2_Y_Vel > 1000) ? 1000 : ParameterHelper.SysParam.EQ.Speed.TrackSW2_Y_Vel;
            AxisRun(Kernel.motion.CV2_TrackSW_Y, ref CV2_TrackSW_Y_Runing, CV2_TrackSW_Y_RunCode, Pos_CV2_TrackSW_Y, 1, speed_Y, acc, dec);

            if (CV2_TrackSW_Y_Homing)
            {
                if (!Kernel.motion.CV2_TrackSW_Y.IsHomeAlready)
                {
                    Kernel.motion.CV2_TrackSW_Y.HomeStart = true;
                }
                CV2_TrackSW_Y_Homing = false;
            }

            if (Kernel.motion.CV2_TrackSW_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.CV2_TrackSW_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CV2_TrackSW_Y.IsHomeAlready == true)
            {
                CV2_TrackSW_Y_LDPt1 =  Kernel.motion.CheckINP(Kernel.motion.CV2_TrackSW_Y.CurrentActPos, Pos_CV2_TrackSW_Y[0], 0.002);
                CV2_TrackSW_Y_LDPt2 =  Kernel.motion.CheckINP(Kernel.motion.CV2_TrackSW_Y.CurrentActPos, Pos_CV2_TrackSW_Y[1], 0.002);
                CV2_TrackSW_Y_Insp1 = Kernel.motion.CheckINP(Kernel.motion.CV2_TrackSW_Y.CurrentActPos, Pos_CV2_TrackSW_Y[2], 0.002);
                CV2_TrackSW_Y_Insp2 = Kernel.motion.CheckINP(Kernel.motion.CV2_TrackSW_Y.CurrentActPos, Pos_CV2_TrackSW_Y[3], 0.002);


                if (CV2_TrackSW_Y_LDPt1 || CV2_TrackSW_Y_LDPt2||CV2_TrackSW_Y_Insp1 || CV2_TrackSW_Y_Insp2)
                {
                    CV2_TrackSW_Y_RunCode = 0;
                }
            }
            else
            {
                CV2_TrackSW_Y_LDPt1 = false;
                CV2_TrackSW_Y_LDPt2 = false;
                CV2_TrackSW_Y_Insp1 = false;
                CV2_TrackSW_Y_Insp2 = false;
            }

            if (Kernel.motion.CV2_TrackSW_Y.AxisMotionIO.SVON == 0 || Kernel.motion.CV2_TrackSW_Y.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.CV2_TrackSW_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CV2_TrackSW_Y_ToHome = false;
            CV2_TrackSW_Y_ToLDPt1= false;
            CV2_TrackSW_Y_ToLDPt2 = false;
            CV2_TrackSW_Y_ToInsp1 = false;
            CV2_TrackSW_Y_ToInsp2 = false;
            #endregion

            #region 状态刷新  
            CV2_TrackSW_Y_LDPt1_BL = PulseOn.Pulse_1s && (CV2_TrackSW_Y_RunCode == 1) || CV2_TrackSW_Y_LDPt1;
            CV2_TrackSW_Y_LDPt2_BL = PulseOn.Pulse_1s && (CV2_TrackSW_Y_RunCode == 2) || CV2_TrackSW_Y_LDPt2;
            CV2_TrackSW_Y_Insp1_BL = PulseOn.Pulse_1s && (CV2_TrackSW_Y_RunCode == 3) || CV2_TrackSW_Y_Insp1;
            CV2_TrackSW_Y_Insp2_BL = PulseOn.Pulse_1s && (CV2_TrackSW_Y_RunCode == 4) || CV2_TrackSW_Y_Insp2;
            CV2_TrackSW_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CV2_TrackSW_Y.IsHomeAlready;
            #endregion
        }
        public void CCD1_XRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_CCD1_X[0] = ParameterHelper.CurParam.CCD1.CH1_Mark.CCD_X;
            Pos_CCD1_X[1] = ParameterHelper.CurParam.CCD1.CH1_Mark.CCD_X;
            Pos_CCD1_X[2] = ParameterHelper.CurParam.CCD1.CH2_Mark.CCD_X;
            Pos_CCD1_X[3] = ParameterHelper.CurParam.CCD1.CH2_Mark.CCD_X;
            Pos_CCD1_X[4] = ParameterHelper.CurParam.CCD1.Wait.CCD_X;


            #endregion

            CCD1_X_Stop = CCD1_X_ToStop || Kernel.motion.CCD1_X.AxisMotionIO.SVON == 0 || (!CCD1_X_AllowMove && (CCD1_X_RunCode > 0));
            CCD1_X_ToStop = false;

            #region          
            if (CCD1_X_Stop)
            {
                if (Kernel.motion.CCD1_X.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.CCD1_X.Stop();
                }
            }

            if (CCD1_X_HomeCondition)
            {
                if ((ManualMode && CCD1_X_ToHome) || CCD1_X_ToHome_A)
                {
                    CCD1_X_Homing = true;
                }
            }

            if (CCD1_X_MoveCondition )
            {
                if ((ManualMode && CCD1_X_ToCH1Mark) || CCD1_X_ToCH1Mark_A)
                {
                    if (!CCD1_X_CH1Mark)
                    {
                        CCD1_X_RunCode = 1;
                    }
                }
                if ((ManualMode && CCD1_X_ToCH1Work) || CCD1_X_ToCH1Work_A)
                {
                    if (!CCD1_X_CH1Work)
                    {
                        CCD1_X_RunCode = 2;
                    }
                }
                if ((ManualMode && CCD1_X_ToCH2Mark) || CCD1_X_ToCH2Mark_A)
                {
                    if (!CCD1_X_CH2Mark)
                    {
                        CCD1_X_RunCode = 3;
                    }
                }
                if ((ManualMode && CCD1_X_ToCH2Work) || CCD1_X_ToCH2Work_A)
                {
                    if (!CCD1_X_CH2Work)
                    {
                        CCD1_X_RunCode = 4;
                    }
                }
                if ((ManualMode && CCD1_X_ToWait) || CCD1_X_ToWait_A)
                {
                    if (!CCD1_X_Wait)
                    {
                        CCD1_X_RunCode = 5;
                    }
                }

                CCD1_X_Runing = CCD1_X_RunCode > 0;
            }

            CCD1_X_HomeCondition = Kernel.motion.CCD1_X.AxisMotionIO.ALM == 0 && Kernel.motion.CCD1_X.AxisMotionStatus.Stop == 1 && CCD1_X_RunCode == 0 && !CCD1_X_Homing && !CCD1_X_Stop;
            CCD1_X_MoveCondition = CCD1_X_HomeCondition && Kernel.motion.CCD1_X.IsHomeAlready && Kernel.motion.CCD1_X.AxisMotionStatus.Stop == 1;

            if (CCD1_X_Stop || Kernel.motion.CCD1_X.AxisMotionIO.ALM == 1)
            {
                CCD1_X_RunCode = 0;
            }

            acc = 0.1;
            dec = 0.1;
            double speed = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CCD1_X_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CCD1_X_Vel;
            AxisRun(Kernel.motion.CCD1_X, ref CCD1_X_Runing, CCD1_X_RunCode, Pos_CCD1_X, 1, speed, acc, dec);

            if (CCD1_X_Homing)
            {
                if (!Kernel.motion.CCD1_X.IsHomeAlready)
                {
                    Kernel.motion.CCD1_X.HomeStart = true;
                }
                CCD1_X_Homing = false;
            }

            if (Kernel.motion.CCD1_X.AxisMotionStatus.Stop == 1 && Kernel.motion.CCD1_X.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CCD1_X.IsHomeAlready == true)
            {
                CCD1_X_CH1Mark = Kernel.motion.CheckINP(Kernel.motion.CCD1_X.CurrentActPos, Pos_CCD1_X[0], 0.002);
                CCD1_X_CH1Work = Kernel.motion.CheckINP(Kernel.motion.CCD1_X.CurrentActPos, Pos_CCD1_X[1], 0.002);
                CCD1_X_CH2Mark = Kernel.motion.CheckINP(Kernel.motion.CCD1_X.CurrentActPos, Pos_CCD1_X[2], 0.002);
                CCD1_X_CH2Work = Kernel.motion.CheckINP(Kernel.motion.CCD1_X.CurrentActPos, Pos_CCD1_X[3], 0.002);
                CCD1_X_Wait = Kernel.motion.CheckINP(Kernel.motion.CCD1_X.CurrentActPos, Pos_CCD1_X[4], 0.002);


                if (CCD1_X_CH1Mark || CCD1_X_CH1Work || CCD1_X_CH2Mark || CCD1_X_CH2Work || CCD1_X_Wait)
                {
                    CCD1_X_RunCode = 0;
                }
            }
            else
            {
                CCD1_X_CH1Mark = false;
                CCD1_X_CH1Work = false;
                CCD1_X_CH2Mark = false;
                CCD1_X_CH2Work = false;
                CCD1_X_Wait = false;
            }

            if (Kernel.motion.CCD1_X.AxisMotionIO.SVON == 0 || Kernel.motion.CCD1_X.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.CCD1_X.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CCD1_X_ToHome = false;
            CCD1_X_ToCH1Mark = false;
            CCD1_X_ToCH1Work = false;
            CCD1_X_ToCH2Mark = false;
            CCD1_X_ToCH2Work = false;
            CCD1_X_ToWait = false;
            #endregion

            #region 状态刷新  
            CCD1_X_CH1Mark_BL = PulseOn.Pulse_1s && (CCD1_X_RunCode == 1) || CCD1_X_CH1Mark;
            CCD1_X_CH1Work_BL = PulseOn.Pulse_1s && (CCD1_X_RunCode == 2) || CCD1_X_CH1Work;
            CCD1_X_CH2Mark_BL = PulseOn.Pulse_1s && (CCD1_X_RunCode == 3) || CCD1_X_CH2Mark;
            CCD1_X_CH2Work_BL = PulseOn.Pulse_1s && (CCD1_X_RunCode == 4) || CCD1_X_CH2Work;
            CCD1_X_Wait_BL = PulseOn.Pulse_1s && (CCD1_X_RunCode == 5) || CCD1_X_Wait;

            CCD1_X_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CCD1_X.IsHomeAlready;
            #endregion
        }
        public void CCD1_YRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_CCD1_Y[0] = ParameterHelper.CurParam.CCD1.CH1_Mark.CCD_Y;
            Pos_CCD1_Y[1] = ParameterHelper.CurParam.CCD1.CH1_Mark.CCD_Y;
            Pos_CCD1_Y[2] = ParameterHelper.CurParam.CCD1.CH2_Mark.CCD_Y;
            Pos_CCD1_Y[3] = ParameterHelper.CurParam.CCD1.CH2_Mark.CCD_Y;
            Pos_CCD1_Y[4] = ParameterHelper.CurParam.CCD1.Wait.CCD_Y;
            #endregion

            CCD1_Y_Stop = CCD1_Y_ToStop || Kernel.motion.CCD1_Y.AxisMotionIO.SVON == 0 || (!CCD1_Y_AllowMove && (CCD1_Y_RunCode > 0));
            CCD1_Y_ToStop = false;

            #region          
            if (CCD1_Y_Stop) { if (Kernel.motion.CCD1_Y.AxisMotionStatus.Stop == 0) { Kernel.motion.CCD1_Y.Stop(); } }
            if (CCD1_Y_HomeCondition) { if ((ManualMode && CCD1_Y_ToHome) || CCD1_Y_ToHome_A) { CCD1_Y_Homing = true; } }               

            if (CCD1_Y_MoveCondition)
            {
                if ((ManualMode && CCD1_Y_ToCH1Mark) || CCD1_Y_ToCH1Mark_A) { if (!CCD1_Y_CH1Mark) { CCD1_Y_RunCode = 1; } }
                if ((ManualMode && CCD1_Y_ToCH1Work) || CCD1_Y_ToCH1Work_A) { if (!CCD1_Y_CH1Work) { CCD1_Y_RunCode = 2; } }
                if ((ManualMode && CCD1_Y_ToCH2Mark) || CCD1_Y_ToCH2Mark_A) { if (!CCD1_Y_CH2Mark) { CCD1_Y_RunCode = 3; } }
                if ((ManualMode && CCD1_Y_ToCH2Work) || CCD1_Y_ToCH2Work_A) { if (!CCD1_Y_CH2Work) { CCD1_Y_RunCode = 4; } }
                if ((ManualMode && CCD1_Y_ToWait) || CCD1_Y_ToWait_A) { if (!CCD1_Y_Wait) { CCD1_Y_RunCode = 5; } }

                CCD1_Y_Runing = CCD1_Y_RunCode > 0;
            }

            CCD1_Y_HomeCondition = Kernel.motion.CCD1_Y.AxisMotionIO.ALM == 0 && Kernel.motion.CCD1_Y.AxisMotionStatus.Stop == 1 && CCD1_Y_RunCode == 0 && !CCD1_Y_Homing && !CCD1_Y_Stop;
            CCD1_Y_MoveCondition = CCD1_Y_HomeCondition && Kernel.motion.CCD1_Y.IsHomeAlready && Kernel.motion.CCD1_Y.AxisMotionStatus.Stop == 1;

            if (CCD1_Y_Stop || Kernel.motion.CCD1_Y.AxisMotionIO.ALM == 1)
            {
                CCD1_Y_RunCode = 0;
            }

            acc = 0.1;
            dec = 0.1;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CCD1_Y_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CCD1_Y_Vel;
            AxisRun(Kernel.motion.CCD1_Y, ref CCD1_Y_Runing, CCD1_Y_RunCode, Pos_CCD1_Y, 1, speed_Y, acc, dec);

            if (CCD1_Y_Homing)
            {
                if (!Kernel.motion.CCD1_Y.IsHomeAlready)
                {
                    Kernel.motion.CCD1_Y.HomeStart = true;
                }
                CCD1_Y_Homing = false;
            }

            if (Kernel.motion.CCD1_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.CCD1_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CCD1_Y.IsHomeAlready == true)
            {
                CCD1_Y_CH1Mark = Kernel.motion.CheckINP(Kernel.motion.CCD1_Y.CurrentActPos, Pos_CCD1_Y[0], 0.002);
                CCD1_Y_CH1Work = Kernel.motion.CheckINP(Kernel.motion.CCD1_Y.CurrentActPos, Pos_CCD1_Y[1], 0.002);
                CCD1_Y_CH2Mark = Kernel.motion.CheckINP(Kernel.motion.CCD1_Y.CurrentActPos, Pos_CCD1_Y[2], 0.002);
                CCD1_Y_CH2Work = Kernel.motion.CheckINP(Kernel.motion.CCD1_Y.CurrentActPos, Pos_CCD1_Y[3], 0.002);
                CCD1_Y_Wait    = Kernel.motion.CheckINP(Kernel.motion.CCD1_Y.CurrentActPos, Pos_CCD1_Y[4], 0.002);


                if (CCD1_Y_CH1Mark 
                 || CCD1_Y_CH1Work 
                 || CCD1_Y_CH2Mark 
                 || CCD1_Y_CH2Work 
                 || CCD1_Y_Wait)
                {
                    CCD1_Y_RunCode = 0;
                }
            }
            else
            {
                CCD1_Y_CH1Mark = false;
                CCD1_Y_CH1Work = false;
                CCD1_Y_CH2Mark = false;
                CCD1_Y_CH2Work = false;
                CCD1_Y_Wait = false;
            }

            if (Kernel.motion.CCD1_Y.AxisMotionIO.SVON == 0 || Kernel.motion.CCD1_Y.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.CCD1_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CCD1_Y_ToHome = false;
            CCD1_Y_ToCH1Mark = false;
            CCD1_Y_ToCH1Work = false;
            CCD1_Y_ToCH2Mark = false;
            CCD1_Y_ToCH2Work = false;
            CCD1_Y_ToWait = false;
            #endregion

            #region 状态刷新  
            CCD1_Y_CH1Mark_BL = PulseOn.Pulse_1s && (CCD1_Y_RunCode == 1) || CCD1_Y_CH1Mark;
            CCD1_Y_CH1Work_BL = PulseOn.Pulse_1s && (CCD1_Y_RunCode == 2) || CCD1_Y_CH1Work;
            CCD1_Y_CH2Mark_BL = PulseOn.Pulse_1s && (CCD1_Y_RunCode == 3) || CCD1_Y_CH2Mark;
            CCD1_Y_CH2Work_BL = PulseOn.Pulse_1s && (CCD1_Y_RunCode == 4) || CCD1_Y_CH2Work;
            CCD1_Y_Wait_BL = PulseOn.Pulse_1s && (CCD1_Y_RunCode == 5) || CCD1_Y_Wait;

            CCD1_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CCD1_Y.IsHomeAlready;
            #endregion
        }
        public void CCD1_ZRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_CCD1_Z[0] = ParameterHelper.CurParam.CCD1.CH1_Mark.CCD_Z;
            Pos_CCD1_Z[1] = ParameterHelper.CurParam.CCD1.CH1_Mark.CCD_Z;
            Pos_CCD1_Z[2] = ParameterHelper.CurParam.CCD1.CH2_Mark.CCD_Z;
            Pos_CCD1_Z[3] = ParameterHelper.CurParam.CCD1.CH2_Mark.CCD_Z;
            Pos_CCD1_Z[4] = ParameterHelper.CurParam.CCD1.Wait.CCD_Z;
            #endregion

            CCD1_Z_Stop = CCD1_Z_ToStop || Kernel.motion.CCD1_Z.AxisMotionIO.SVON == 0 || (!CCD1_Z_AllowMove && (CCD1_Z_RunCode > 0));
            CCD1_Z_ToStop = false;

            #region          
            if (CCD1_Z_Stop) { if (Kernel.motion.CCD1_Z.AxisMotionStatus.Stop == 0) { Kernel.motion.CCD1_Z.Stop(); } }
            if (CCD1_Z_HomeCondition) { if ((ManualMode && CCD1_Z_ToHome) || CCD1_Z_ToHome_A) { CCD1_Z_Homing = true; } }

            if (CCD1_Z_MoveCondition )
            {
                if ((ManualMode && CCD1_Z_ToCH1Mark) || CCD1_Z_ToCH1Mark_A) { if (!CCD1_Z_CH1Mark) { CCD1_Z_RunCode = 1; } }
                if ((ManualMode && CCD1_Z_ToCH1Work) || CCD1_Z_ToCH1Work_A) { if (!CCD1_Z_CH1Work) { CCD1_Z_RunCode = 2; } }
                if ((ManualMode && CCD1_Z_ToCH1Mark) || CCD1_Z_ToCH1Mark_A) { if (!CCD1_Z_CH2Mark) { CCD1_Z_RunCode = 3; } }
                if ((ManualMode && CCD1_Z_ToCH1Work) || CCD1_Z_ToCH1Work_A) { if (!CCD1_Z_CH2Work) { CCD1_Z_RunCode = 4; } }
                if ((ManualMode && CCD1_Z_ToWait) || CCD1_Z_ToWait_A) { if (!CCD1_Z_Wait) { CCD1_Z_RunCode = 5; } }

                CCD1_Z_Runing = CCD1_Z_RunCode > 0;
            }

            CCD1_Z_HomeCondition = Kernel.motion.CCD1_Z.AxisMotionIO.ALM == 0 && Kernel.motion.CCD1_Z.AxisMotionStatus.Stop == 1 && CCD1_Z_RunCode == 0 && !CCD1_Z_Homing && !CCD1_Z_Stop;
            CCD1_Z_MoveCondition = CCD1_Z_HomeCondition && Kernel.motion.CCD1_Z.IsHomeAlready && Kernel.motion.CCD1_Z.AxisMotionStatus.Stop == 1;

            if (CCD1_Z_Stop || Kernel.motion.CCD1_Z.AxisMotionIO.ALM == 1)
            {
                CCD1_Z_RunCode = 0;
            }

            acc = 0.1;
            dec = 0.1;
            double speed_Z = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CCD1_Z_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CCD1_Z_Vel;
            AxisRun(Kernel.motion.CCD1_Z, ref CCD1_Z_Runing, CCD1_Z_RunCode, Pos_CCD1_Z, 1, speed_Z, acc, dec);

            if (CCD1_Z_Homing)
            {
                if (!Kernel.motion.CCD1_Z.IsHomeAlready)
                {
                    Kernel.motion.CCD1_Z.HomeStart = true;
                }
                CCD1_Z_Homing = false;
            }
            CCD1_Z_Homed = Kernel.motion.CCD1_Z.IsHomeAlready;
            if (Kernel.motion.CCD1_Z.AxisMotionStatus.Stop == 1 && Kernel.motion.CCD1_Z.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CCD1_Z.IsHomeAlready == true)
            {
                CCD1_Z_CH1Mark = Kernel.motion.CheckINP(Kernel.motion.CCD1_Z.CurrentActPos, Pos_CCD1_Z[0], 0.002);
                CCD1_Z_CH1Work = Kernel.motion.CheckINP(Kernel.motion.CCD1_Z.CurrentActPos, Pos_CCD1_Z[1], 0.002);
                CCD1_Z_CH2Mark = Kernel.motion.CheckINP(Kernel.motion.CCD1_Z.CurrentActPos, Pos_CCD1_Z[2], 0.002);
                CCD1_Z_CH2Work = Kernel.motion.CheckINP(Kernel.motion.CCD1_Z.CurrentActPos, Pos_CCD1_Z[3], 0.002);
                CCD1_Z_Wait = Kernel.motion.CheckINP(Kernel.motion.CCD1_Z.CurrentActPos, Pos_CCD1_Z[4], 0.002);


                if (CCD1_Z_CH1Mark
                 || CCD1_Z_CH1Work
                 || CCD1_Z_CH2Mark
                 || CCD1_Z_CH2Work
                 || CCD1_Z_Wait)
                {
                    CCD1_Z_RunCode = 0;
                }
            }
            else
            {
                CCD1_Z_CH1Mark = false;
                CCD1_Z_CH1Work = false;
                CCD1_Z_CH2Mark = false;
                CCD1_Z_CH2Work = false;
                CCD1_Z_Wait = false;
            }

            if (Kernel.motion.CCD1_Z.AxisMotionIO.SVON == 0 || Kernel.motion.CCD1_Z.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.CCD1_Z.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CCD1_Z_ToHome = false;
            CCD1_Z_ToCH1Mark = false;
            CCD1_Z_ToCH1Work = false;
            CCD1_Z_ToCH2Mark = false;
            CCD1_Z_ToCH2Work = false;
            CCD1_Z_ToWait = false;
            #endregion

            #region 状态刷新  
            CCD1_Z_CH1Mark_BL = PulseOn.Pulse_1s && (CCD1_Z_RunCode == 1) || CCD1_Z_CH1Mark;
            CCD1_Z_CH1Work_BL = PulseOn.Pulse_1s && (CCD1_Z_RunCode == 2) || CCD1_Z_CH1Work;
            CCD1_Z_CH2Mark_BL = PulseOn.Pulse_1s && (CCD1_Z_RunCode == 3) || CCD1_Z_CH2Mark;
            CCD1_Z_CH2Work_BL = PulseOn.Pulse_1s && (CCD1_Z_RunCode == 4) || CCD1_Z_CH2Work;
            CCD1_Z_Wait_BL = PulseOn.Pulse_1s && (CCD1_Z_RunCode == 5) || CCD1_Z_Wait;

            CCD1_Z_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CCD1_Z.IsHomeAlready;
            #endregion
        }
        public void CCD2_XRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_CCD2_X[0] = ParameterHelper.CurParam.CCD2.CH1_Mark.CCD_X;
            Pos_CCD2_X[1] = ParameterHelper.CurParam.CCD2.CH1_Mark.CCD_X;
            Pos_CCD2_X[2] = ParameterHelper.CurParam.CCD2.CH2_Mark.CCD_X;
            Pos_CCD2_X[3] = ParameterHelper.CurParam.CCD2.CH2_Mark.CCD_X;
            Pos_CCD2_X[4] = ParameterHelper.CurParam.CCD2.Wait.CCD_X;


            #endregion

            CCD2_X_Stop = CCD2_X_ToStop || Kernel.motion.CCD2_X.AxisMotionIO.SVON == 0 || (!CCD2_X_AllowMove && (CCD2_X_RunCode > 0));
            CCD2_X_ToStop = false;

            #region          
            if (CCD2_X_Stop)
            {
                if (Kernel.motion.CCD2_X.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.CCD2_X.Stop();
                }
            }

            if (CCD2_X_HomeCondition)
            {
                if ((ManualMode && CCD2_X_ToHome) || CCD2_X_ToHome_A)
                {
                    CCD2_X_Homing = true;
                }
            }

            if (CCD2_X_MoveCondition)
            {
                if ((ManualMode && CCD2_X_ToCH1Mark) || CCD2_X_ToCH1Mark_A)
                {
                    if (!CCD2_X_CH1Mark)
                    {
                        CCD2_X_RunCode = 1;
                    }
                }
                if ((ManualMode && CCD2_X_ToCH1Work) || CCD2_X_ToCH1Work_A)
                {
                    if (!CCD2_X_CH1Work)
                    {
                        CCD2_X_RunCode = 2;
                    }
                }
                if ((ManualMode && CCD2_X_ToCH2Mark) || CCD2_X_ToCH2Mark_A)
                {
                    if (!CCD2_X_CH2Mark)
                    {
                        CCD2_X_RunCode = 3;
                    }
                }
                if ((ManualMode && CCD2_X_ToCH2Work) || CCD2_X_ToCH2Work_A)
                {
                    if (!CCD2_X_CH2Work)
                    {
                        CCD2_X_RunCode = 4;
                    }
                }
                if ((ManualMode && CCD2_X_ToWait) || CCD2_X_ToWait_A)
                {
                    if (!CCD2_X_Wait)
                    {
                        CCD2_X_RunCode = 5;
                    }
                }

                CCD2_X_Runing = CCD2_X_RunCode > 0;
            }

            CCD2_X_HomeCondition = Kernel.motion.CCD2_X.AxisMotionIO.ALM == 0 && Kernel.motion.CCD2_X.AxisMotionStatus.Stop == 1 && CCD2_X_RunCode == 0 && !CCD2_X_Homing && !CCD2_X_Stop;
            CCD2_X_MoveCondition = CCD2_X_HomeCondition && Kernel.motion.CCD2_X.IsHomeAlready && Kernel.motion.CCD2_X.AxisMotionStatus.Stop == 1;

            if (CCD2_X_Stop || Kernel.motion.CCD2_X.AxisMotionIO.ALM == 1)
            {
                CCD2_X_RunCode = 0;
            }

            acc = 0.1;
            dec = 0.1;
            double speed = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CCD2_X_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CCD2_X_Vel;
            AxisRun(Kernel.motion.CCD2_X, ref CCD2_X_Runing, CCD2_X_RunCode, Pos_CCD2_X, 1, speed, acc, dec);

            if (CCD2_X_Homing)
            {
                if (!Kernel.motion.CCD2_X.IsHomeAlready)
                {
                    Kernel.motion.CCD2_X.HomeStart = true;
                }
                CCD2_X_Homing = false;
            }

            if (Kernel.motion.CCD2_X.AxisMotionStatus.Stop == 1 && Kernel.motion.CCD2_X.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CCD2_X.IsHomeAlready == true)
            {
                CCD2_X_CH1Mark = Kernel.motion.CheckINP(Kernel.motion.CCD2_X.CurrentActPos, Pos_CCD2_X[0], 0.002);
                CCD2_X_CH1Work = Kernel.motion.CheckINP(Kernel.motion.CCD2_X.CurrentActPos, Pos_CCD2_X[1], 0.002);
                CCD2_X_CH2Mark = Kernel.motion.CheckINP(Kernel.motion.CCD2_X.CurrentActPos, Pos_CCD2_X[2], 0.002);
                CCD2_X_CH2Work = Kernel.motion.CheckINP(Kernel.motion.CCD2_X.CurrentActPos, Pos_CCD2_X[3], 0.002);
                CCD2_X_Wait = Kernel.motion.CheckINP(Kernel.motion.CCD2_X.CurrentActPos, Pos_CCD2_X[4], 0.002);


                if (CCD2_X_CH1Mark || CCD2_X_CH1Work || CCD2_X_CH2Mark || CCD2_X_CH2Work || CCD2_X_Wait)
                {
                    CCD2_X_RunCode = 0;
                }
            }
            else
            {
                CCD2_X_CH1Mark = false;
                CCD2_X_CH1Work = false;
                CCD2_X_CH2Mark = false;
                CCD2_X_CH2Work = false;
                CCD2_X_Wait = false;
            }

            if (Kernel.motion.CCD2_X.AxisMotionIO.SVON == 0 || Kernel.motion.CCD2_X.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.CCD2_X.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CCD2_X_ToHome = false;
            CCD2_X_ToCH1Mark = false;
            CCD2_X_ToCH1Work = false;
            CCD2_X_ToCH2Mark = false;
            CCD2_X_ToCH2Work = false;
            CCD2_X_ToWait = false;
            #endregion

            #region 状态刷新  
            CCD2_X_CH1Mark_BL = PulseOn.Pulse_1s && (CCD2_X_RunCode == 1) || CCD2_X_CH1Mark;
            CCD2_X_CH1Work_BL = PulseOn.Pulse_1s && (CCD2_X_RunCode == 2) || CCD2_X_CH1Work;
            CCD2_X_CH2Mark_BL = PulseOn.Pulse_1s && (CCD2_X_RunCode == 3) || CCD2_X_CH2Mark;
            CCD2_X_CH2Work_BL = PulseOn.Pulse_1s && (CCD2_X_RunCode == 4) || CCD2_X_CH2Work;
            CCD2_X_Wait_BL = PulseOn.Pulse_1s && (CCD2_X_RunCode == 5) || CCD2_X_Wait;

            CCD2_X_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CCD2_X.IsHomeAlready;
            #endregion
        }
        public void CCD2_YRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_CCD2_Y[0] = ParameterHelper.CurParam.CCD2.CH1_Mark.CCD_Y;
            Pos_CCD2_Y[1] = ParameterHelper.CurParam.CCD2.CH1_Insp.CCD_Y;
            Pos_CCD2_Y[2] = ParameterHelper.CurParam.CCD2.CH2_Mark.CCD_Y;
            Pos_CCD2_Y[3] = ParameterHelper.CurParam.CCD2.CH2_Insp.CCD_Y;
            Pos_CCD2_Y[4] = ParameterHelper.CurParam.CCD2.Wait.CCD_Y;
            #endregion

            CCD2_Y_Stop = CCD2_Y_ToStop || Kernel.motion.CCD2_Y.AxisMotionIO.SVON == 0 || (!CCD2_Y_AllowMove && (CCD2_Y_RunCode > 0));
            CCD2_Y_ToStop = false;

            #region          
            if (CCD2_Y_Stop) { if (Kernel.motion.CCD2_Y.AxisMotionStatus.Stop == 0) { Kernel.motion.CCD2_Y.Stop(); } }
            if (CCD2_Y_HomeCondition) { if ((ManualMode && CCD2_Y_ToHome) || CCD2_Y_ToHome_A) { CCD2_Y_Homing = true; } }

            if (CCD2_Y_MoveCondition)
            {
                if ((ManualMode && CCD2_Y_ToCH1Mark) || CCD2_Y_ToCH1Mark_A) { if (!CCD2_Y_CH1Mark) { CCD2_Y_RunCode = 1; } }
                if ((ManualMode && CCD2_Y_ToCH1Work) || CCD2_Y_ToCH1Work_A) { if (!CCD2_Y_CH1Work) { CCD2_Y_RunCode = 2; } }
                if ((ManualMode && CCD2_Y_ToCH2Mark) || CCD2_Y_ToCH2Mark_A) { if (!CCD2_Y_CH2Mark) { CCD2_Y_RunCode = 3; } }
                if ((ManualMode && CCD2_Y_ToCH2Work) || CCD2_Y_ToCH2Work_A) { if (!CCD2_Y_CH2Work) { CCD2_Y_RunCode = 4; } }
                if ((ManualMode && CCD2_Y_ToWait) || CCD2_Y_ToWait_A) { if (!CCD2_Y_Wait) { CCD2_Y_RunCode = 5; } }

                CCD2_Y_Runing = CCD2_Y_RunCode > 0;
            }

            CCD2_Y_HomeCondition = Kernel.motion.CCD2_Y.AxisMotionIO.ALM == 0 && Kernel.motion.CCD2_Y.AxisMotionStatus.Stop == 1 && CCD2_Y_RunCode == 0 && !CCD2_Y_Homing && !CCD2_Y_Stop;
            CCD2_Y_MoveCondition = CCD2_Y_HomeCondition && Kernel.motion.CCD2_Y.IsHomeAlready && Kernel.motion.CCD2_Y.AxisMotionStatus.Stop == 1;

            if (CCD2_Y_Stop || Kernel.motion.CCD2_Y.AxisMotionIO.ALM == 1)
            {
                CCD2_Y_RunCode = 0;
            }

            acc = 0.1;
            dec = 0.1;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CCD2_Y_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CCD2_Y_Vel;
            AxisRun(Kernel.motion.CCD2_Y, ref CCD2_Y_Runing, CCD2_Y_RunCode, Pos_CCD2_Y, 1, speed_Y, acc, dec);

            if (CCD2_Y_Homing)
            {
                if (!Kernel.motion.CCD2_Y.IsHomeAlready)
                {
                    Kernel.motion.CCD2_Y.HomeStart = true;
                }
                CCD2_Y_Homing = false;
            }

            if (Kernel.motion.CCD2_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.CCD2_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CCD2_Y.IsHomeAlready == true)
            {
                CCD2_Y_CH1Mark = Kernel.motion.CheckINP(Kernel.motion.CCD2_Y.CurrentActPos, Pos_CCD2_Y[0], 0.002);
                CCD2_Y_CH1Work = Kernel.motion.CheckINP(Kernel.motion.CCD2_Y.CurrentActPos, Pos_CCD2_Y[1], 0.002);
                CCD2_Y_CH2Mark = Kernel.motion.CheckINP(Kernel.motion.CCD2_Y.CurrentActPos, Pos_CCD2_Y[2], 0.002);
                CCD2_Y_CH2Work = Kernel.motion.CheckINP(Kernel.motion.CCD2_Y.CurrentActPos, Pos_CCD2_Y[3], 0.002);
                CCD2_Y_Wait = Kernel.motion.CheckINP(Kernel.motion.CCD2_Y.CurrentActPos, Pos_CCD2_Y[4], 0.002);


                if (CCD2_Y_CH1Mark
                 || CCD2_Y_CH1Work
                 || CCD2_Y_CH2Mark
                 || CCD2_Y_CH2Work
                 || CCD2_Y_Wait)
                {
                    CCD2_Y_RunCode = 0;
                }
            }
            else
            {
                CCD2_Y_CH1Mark = false;
                CCD2_Y_CH1Work = false;
                CCD2_Y_CH2Mark = false;
                CCD2_Y_CH2Work = false;
                CCD2_Y_Wait = false;
            }

            if (Kernel.motion.CCD2_Y.AxisMotionIO.SVON == 0 || Kernel.motion.CCD2_Y.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.CCD2_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CCD2_Y_ToHome = false;
            CCD2_Y_ToCH1Mark = false;
            CCD2_Y_ToCH1Work = false;
            CCD2_Y_ToCH2Mark = false;
            CCD2_Y_ToCH2Work = false;
            CCD2_Y_ToWait = false;
            #endregion

            #region 状态刷新  
            CCD2_Y_CH1Mark_BL = PulseOn.Pulse_1s && (CCD2_Y_RunCode == 1) || CCD2_Y_CH1Mark;
            CCD2_Y_CH1Work_BL = PulseOn.Pulse_1s && (CCD2_Y_RunCode == 2) || CCD2_Y_CH1Work;
            CCD2_Y_CH2Mark_BL = PulseOn.Pulse_1s && (CCD2_Y_RunCode == 3) || CCD2_Y_CH2Mark;
            CCD2_Y_CH2Work_BL = PulseOn.Pulse_1s && (CCD2_Y_RunCode == 4) || CCD2_Y_CH2Work;
            CCD2_Y_Wait_BL = PulseOn.Pulse_1s && (CCD2_Y_RunCode == 5) || CCD2_Y_Wait;

            CCD2_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CCD2_Y.IsHomeAlready;
            #endregion
        }
        public void CCD2_ZRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_CCD2_Z[0] = ParameterHelper.CurParam.CCD2.CH1_Mark.CCD_Z;
            Pos_CCD2_Z[1] = ParameterHelper.CurParam.CCD2.CH1_Mark.CCD_Z;
            Pos_CCD2_Z[2] = ParameterHelper.CurParam.CCD2.CH2_Mark.CCD_Z;
            Pos_CCD2_Z[3] = ParameterHelper.CurParam.CCD2.CH2_Mark.CCD_Z;
            Pos_CCD2_Z[4] = ParameterHelper.CurParam.CCD2.Wait.CCD_Z;
            #endregion

            CCD2_Z_Stop = CCD2_Z_ToStop || Kernel.motion.CCD2_Z.AxisMotionIO.SVON == 0 || (!CCD2_Z_AllowMove && (CCD2_Z_RunCode > 0));
            CCD2_Z_ToStop = false;

            #region          
            if (CCD2_Z_Stop) { if (Kernel.motion.CCD2_Z.AxisMotionStatus.Stop == 0) { Kernel.motion.CCD2_Z.Stop(); } }
            if (CCD2_Z_HomeCondition) { if ((ManualMode && CCD2_Z_ToHome) || CCD2_Z_ToHome_A) { CCD2_Z_Homing = true; } }

            if (CCD2_Z_MoveCondition)
            {
                if ((ManualMode && CCD2_Z_ToCH1Mark) || CCD2_Z_ToCH1Mark_A) { if (!CCD2_Z_CH1Mark) { CCD2_Z_RunCode = 1; } }
                if ((ManualMode && CCD2_Z_ToCH1Work) || CCD2_Z_ToCH1Work_A) { if (!CCD2_Z_CH1Work) { CCD2_Z_RunCode = 2; } }
                if ((ManualMode && CCD2_Z_ToCH1Mark) || CCD2_Z_ToCH1Mark_A) { if (!CCD2_Z_CH2Mark) { CCD2_Z_RunCode = 3; } }
                if ((ManualMode && CCD2_Z_ToCH1Work) || CCD2_Z_ToCH1Work_A) { if (!CCD2_Z_CH2Work) { CCD2_Z_RunCode = 4; } }
                if ((ManualMode && CCD2_Z_ToWait) || CCD2_Z_ToWait_A) { if (!CCD2_Z_Wait) { CCD2_Z_RunCode = 5; } }

                CCD2_Z_Runing = CCD2_Z_RunCode > 0;
            }

            CCD2_Z_HomeCondition = Kernel.motion.CCD2_Z.AxisMotionIO.ALM == 0 && Kernel.motion.CCD2_Z.AxisMotionStatus.Stop == 1 && CCD2_Z_RunCode == 0 && !CCD2_Z_Homing && !CCD2_Z_Stop;
            CCD2_Z_MoveCondition = CCD2_Z_HomeCondition && Kernel.motion.CCD2_Z.IsHomeAlready && Kernel.motion.CCD2_Z.AxisMotionStatus.Stop == 1;

            if (CCD2_Z_Stop || Kernel.motion.CCD2_Z.AxisMotionIO.ALM == 1)
            {
                CCD2_Z_RunCode = 0;
            }

            acc = 0.1;
            dec = 0.1;
            double speed_Z = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CCD2_Z_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CCD2_Z_Vel;
            AxisRun(Kernel.motion.CCD2_Z, ref CCD2_Z_Runing, CCD2_Z_RunCode, Pos_CCD2_Z, 1, speed_Z, acc, dec);

            if (CCD2_Z_Homing)
            {
                if (!Kernel.motion.CCD2_Z.IsHomeAlready)
                {
                    Kernel.motion.CCD2_Z.HomeStart = true;
                }
                CCD2_Z_Homing = false;
            }
            CCD2_Z_Homed = Kernel.motion.CCD2_Z.IsHomeAlready;
            if (Kernel.motion.CCD2_Z.AxisMotionStatus.Stop == 1 && Kernel.motion.CCD2_Z.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CCD2_Z.IsHomeAlready == true)
            {
                CCD2_Z_CH1Mark = Kernel.motion.CheckINP(Kernel.motion.CCD2_Z.CurrentActPos, Pos_CCD2_Z[0], 0.002);
                CCD2_Z_CH1Work = Kernel.motion.CheckINP(Kernel.motion.CCD2_Z.CurrentActPos, Pos_CCD2_Z[1], 0.002);
                CCD2_Z_CH2Mark = Kernel.motion.CheckINP(Kernel.motion.CCD2_Z.CurrentActPos, Pos_CCD2_Z[2], 0.002);
                CCD2_Z_CH2Work = Kernel.motion.CheckINP(Kernel.motion.CCD2_Z.CurrentActPos, Pos_CCD2_Z[3], 0.002);
                CCD2_Z_Wait = Kernel.motion.CheckINP(Kernel.motion.CCD2_Z.CurrentActPos, Pos_CCD2_Z[4], 0.002);


                if (CCD2_Z_CH1Mark
                 || CCD2_Z_CH1Work
                 || CCD2_Z_CH2Mark
                 || CCD2_Z_CH2Work
                 || CCD2_Z_Wait)
                {
                    CCD2_Z_RunCode = 0;
                }
            }
            else
            {
                CCD2_Z_CH1Mark = false;
                CCD2_Z_CH1Work = false;
                CCD2_Z_CH2Mark = false;
                CCD2_Z_CH2Work = false;
                CCD2_Z_Wait = false;
            }

            if (Kernel.motion.CCD2_Z.AxisMotionIO.SVON == 0 || Kernel.motion.CCD2_Z.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.CCD2_Z.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CCD2_Z_ToHome = false;
            CCD2_Z_ToCH1Mark = false;
            CCD2_Z_ToCH1Work = false;
            CCD2_Z_ToCH2Mark = false;
            CCD2_Z_ToCH2Work = false;
            CCD2_Z_ToWait = false;
            #endregion

            #region 状态刷新  
            CCD2_Z_CH1Mark_BL = PulseOn.Pulse_1s && (CCD2_Z_RunCode == 1) || CCD2_Z_CH1Mark;
            CCD2_Z_CH1Work_BL = PulseOn.Pulse_1s && (CCD2_Z_RunCode == 2) || CCD2_Z_CH1Work;
            CCD2_Z_CH2Mark_BL = PulseOn.Pulse_1s && (CCD2_Z_RunCode == 3) || CCD2_Z_CH2Mark;
            CCD2_Z_CH2Work_BL = PulseOn.Pulse_1s && (CCD2_Z_RunCode == 4) || CCD2_Z_CH2Work;
            CCD2_Z_Wait_BL = PulseOn.Pulse_1s && (CCD2_Z_RunCode == 5) || CCD2_Z_Wait;

            CCD2_Z_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CCD2_Z.IsHomeAlready;
            #endregion
        }
        public void CV1_YRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_CV1_Y[0] = ParameterHelper.CurParam.CV1_Y.Wait;
            Pos_CV1_Y[1] = ParameterHelper.CurParam.CV1_Y.Work;
           
            #endregion

            CV1_Y_Stop = CV1_Y_ToStop || Kernel.motion.CV1_Y.AxisMotionIO.SVON == 0 || (!CV1_Y_AllowMove && (CV1_Y_RunCode > 0));
            CV1_Y_ToStop = false;

            #region          
            if (CV1_Y_Stop) { if (Kernel.motion.CV1_Y.AxisMotionStatus.Stop == 0) { Kernel.motion.CV1_Y.Stop(); } }
            if (CV1_Y_HomeCondition) { if ((ManualMode && CV1_Y_ToHome) || CV1_Y_ToHome_A) { CV1_Y_Homing = true; } }

            if (CV1_Y_MoveCondition)
            {
                if ((ManualMode && CV1_Y_ToWait) || CV1_Y_ToWait_A) { if (!CV1_Y_Wait) { CV1_Y_RunCode = 1; } }
                if ((ManualMode && CV1_Y_ToWork) || CV1_Y_ToWork_A) { if (!CV1_Y_Work) { CV1_Y_RunCode = 2; } }

                CV1_Y_Runing = CV1_Y_RunCode > 0;
            }

            CV1_Y_HomeCondition = Kernel.motion.CV1_Y.AxisMotionIO.ALM == 0 && Kernel.motion.CV1_Y.AxisMotionStatus.Stop == 1 && CV1_Y_RunCode == 0 && !CV1_Y_Homing && !CV1_Y_Stop;
            CV1_Y_MoveCondition = CV1_Y_HomeCondition && Kernel.motion.CV1_Y.IsHomeAlready && Kernel.motion.CV1_Y.AxisMotionStatus.Stop == 1;

            if (CV1_Y_Stop || Kernel.motion.CV1_Y.AxisMotionIO.ALM == 1)
            {
                CV1_Y_RunCode = 0;
            }

            acc = 0.1;
            dec = 0.1;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CV_Y_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CV_Y_Vel;
            AxisRun(Kernel.motion.CV1_Y, ref CV1_Y_Runing, CV1_Y_RunCode, Pos_CV1_Y, 1, speed_Y, acc, dec);

            if (CV1_Y_Homing)
            {
                if (!Kernel.motion.CV1_Y.IsHomeAlready)
                {
                    Kernel.motion.CV1_Y.HomeStart = true;
                }
                CV1_Y_Homing = false;
            }

            if (Kernel.motion.CV1_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.CV1_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CV1_Y.IsHomeAlready == true)
            {
                CV1_Y_Wait = Kernel.motion.CheckINP(Kernel.motion.CV1_Y.CurrentActPos, Pos_CV1_Y[0], 0.002);
                CV1_Y_Work = Kernel.motion.CheckINP(Kernel.motion.CV1_Y.CurrentActPos, Pos_CV1_Y[1], 0.002);
                
                if (CV1_Y_Wait
                 || CV1_Y_Work)
                {
                    CV1_Y_RunCode = 0;
                }
            }
            else
            {
                CV1_Y_Wait = false;
                CV1_Y_Work = false;
            }

            if (Kernel.motion.CV1_Y.AxisMotionIO.SVON == 0 || Kernel.motion.CV1_Y.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.CV1_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CV1_Y_ToHome = false;
            CV1_Y_ToWait = false;
            CV1_Y_ToWork = false;
            #endregion

            #region 状态刷新  
            CV1_Y_Wait_BL = PulseOn.Pulse_1s && (CV1_Y_RunCode == 1) || CV1_Y_Wait ;
            CV1_Y_Work_BL = PulseOn.Pulse_1s && (CV1_Y_RunCode == 2) || CV1_Y_Work;

            CV1_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CV1_Y.IsHomeAlready;
            #endregion
        }
        public void CV2_YRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_CV2_Y[0] = ParameterHelper.CurParam.CV2_Y.Wait;
            Pos_CV2_Y[1] = ParameterHelper.CurParam.CV2_Y.Work;

            #endregion

            CV2_Y_Stop = CV2_Y_ToStop || Kernel.motion.CV2_Y.AxisMotionIO.SVON == 0 || (!CV2_Y_AllowMove && (CV2_Y_RunCode > 0));
            CV2_Y_ToStop = false;

            #region          
            if (CV2_Y_Stop) { if (Kernel.motion.CV2_Y.AxisMotionStatus.Stop == 0) { Kernel.motion.CV2_Y.Stop(); } }
            if (CV2_Y_HomeCondition) { if ((ManualMode && CV2_Y_ToHome) || CV2_Y_ToHome_A) { CV2_Y_Homing = true; } }

            if (CV2_Y_MoveCondition)
            {
                if ((ManualMode && CV2_Y_ToWait) || CV2_Y_ToWait_A) { if (!CV2_Y_Wait) { CV2_Y_RunCode = 1; } }
                if ((ManualMode && CV2_Y_ToWork) || CV2_Y_ToWork_A) { if (!CV2_Y_Work) { CV2_Y_RunCode = 2; } }

                CV2_Y_Runing = CV2_Y_RunCode > 0;
            }

            CV2_Y_HomeCondition = Kernel.motion.CV2_Y.AxisMotionIO.ALM == 0 && Kernel.motion.CV2_Y.AxisMotionStatus.Stop == 1 && CV2_Y_RunCode == 0 && !CV2_Y_Homing && !CV2_Y_Stop;
            CV2_Y_MoveCondition = CV2_Y_HomeCondition && Kernel.motion.CV2_Y.IsHomeAlready && Kernel.motion.CV2_Y.AxisMotionStatus.Stop == 1;

            if (CV2_Y_Stop || Kernel.motion.CV2_Y.AxisMotionIO.ALM == 1)
            {
                CV2_Y_RunCode = 0;
            }

            acc = 0.1;
            dec = 0.1;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CV_Y_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CV_Y_Vel;
            AxisRun(Kernel.motion.CV2_Y, ref CV2_Y_Runing, CV2_Y_RunCode, Pos_CV2_Y, 1, speed_Y, acc, dec);

            if (CV2_Y_Homing)
            {
                if (!Kernel.motion.CV2_Y.IsHomeAlready)
                {
                    Kernel.motion.CV2_Y.HomeStart = true;
                }
                CV2_Y_Homing = false;
            }

            if (Kernel.motion.CV2_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.CV2_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.CV2_Y.IsHomeAlready == true)
            {
                CV2_Y_Wait = Kernel.motion.CheckINP(Kernel.motion.CV2_Y.CurrentActPos, Pos_CV2_Y[0], 0.002);
                CV2_Y_Work = Kernel.motion.CheckINP(Kernel.motion.CV2_Y.CurrentActPos, Pos_CV2_Y[1], 0.002);

                if (CV2_Y_Wait
                 || CV2_Y_Work)
                {
                    CV2_Y_RunCode = 0;
                }
            }
            else
            {
                CV2_Y_Wait = false;
                CV2_Y_Work = false;
            }

            if (Kernel.motion.CV2_Y.AxisMotionIO.SVON == 0 || Kernel.motion.CV2_Y.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.CV2_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            CV2_Y_ToHome = false;
            CV2_Y_ToWait = false;
            CV2_Y_ToWork = false;
            #endregion

            #region 状态刷新  
            CV2_Y_Wait_BL = PulseOn.Pulse_1s && (CV2_Y_RunCode == 1) || CV2_Y_Wait;
            CV2_Y_Work_BL = PulseOn.Pulse_1s && (CV2_Y_RunCode == 2) || CV2_Y_Work;

            CV2_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.CV2_Y.IsHomeAlready;
            #endregion
        }
        public void Insp1_YRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_Insp1_Y[0] = ParameterHelper.CurParam.Insp1_Y.Wait;
            Pos_Insp1_Y[1] = ParameterHelper.CurParam.Insp1_Y.Work;

            #endregion

            Insp1_Y_Stop = Insp1_Y_ToStop || Kernel.motion.Insp1_Y.AxisMotionIO.SVON == 0 || (!Insp1_Y_AllowMove && (Insp1_Y_RunCode > 0));
            Insp1_Y_ToStop = false;

            #region          
            if (Insp1_Y_Stop) { if (Kernel.motion.Insp1_Y.AxisMotionStatus.Stop == 0) { Kernel.motion.Insp1_Y.Stop(); } }
            if (Insp1_Y_HomeCondition) { if ((ManualMode && Insp1_Y_ToHome) || Insp1_Y_ToHome_A) { Insp1_Y_Homing = true; } }

            if (Insp1_Y_MoveCondition)
            {
                if ((ManualMode && Insp1_Y_ToWait) || Insp1_Y_ToWait_A) { if (!Insp1_Y_Wait) { Insp1_Y_RunCode = 1; } }
                if ((ManualMode && Insp1_Y_ToWork) || Insp1_Y_ToWork_A) { if (!Insp1_Y_Work) { Insp1_Y_RunCode = 2; } }

                Insp1_Y_Runing = Insp1_Y_RunCode > 0;
            }

            Insp1_Y_HomeCondition = Kernel.motion.Insp1_Y.AxisMotionIO.ALM == 0 && Kernel.motion.Insp1_Y.AxisMotionStatus.Stop == 1 && Insp1_Y_RunCode == 0 && !Insp1_Y_Homing && !Insp1_Y_Stop;
            Insp1_Y_MoveCondition = Insp1_Y_HomeCondition && Kernel.motion.Insp1_Y.IsHomeAlready && Kernel.motion.Insp1_Y.AxisMotionStatus.Stop == 1;

            if (Insp1_Y_Stop || Kernel.motion.Insp1_Y.AxisMotionIO.ALM == 1)
            {
                Insp1_Y_RunCode = 0;
            }

            acc = 0.5;
            dec = 0.5;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.Insp1_Y_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.Insp1_Y_Vel;
            AxisRun(Kernel.motion.Insp1_Y, ref Insp1_Y_Runing, Insp1_Y_RunCode, Pos_Insp1_Y, 1, speed_Y, acc, dec);

            if (Insp1_Y_Homing)
            {
                if (!Kernel.motion.Insp1_Y.IsHomeAlready)
                {
                    Kernel.motion.Insp1_Y.HomeStart = true;
                }
                Insp1_Y_Homing = false;
            }

            if (Kernel.motion.Insp1_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.Insp1_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.Insp1_Y.IsHomeAlready == true)
            {
                Insp1_Y_Wait = Kernel.motion.CheckINP(Kernel.motion.Insp1_Y.CurrentActPos, Pos_Insp1_Y[0], 0.002);
                Insp1_Y_Work = Kernel.motion.CheckINP(Kernel.motion.Insp1_Y.CurrentActPos, Pos_Insp1_Y[1], 0.002);

                if (Insp1_Y_Wait
                 || Insp1_Y_Work)
                {
                    Insp1_Y_RunCode = 0;
                }
            }
            else
            {
                Insp1_Y_Wait = false;
                Insp1_Y_Work = false;
            }

            if (Kernel.motion.Insp1_Y.AxisMotionIO.SVON == 0 || Kernel.motion.Insp1_Y.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.Insp1_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            Insp1_Y_ToHome = false;
            Insp1_Y_ToWait = false;
            Insp1_Y_ToWork = false;
            #endregion

            #region 状态刷新  
            Insp1_Y_Wait_BL = PulseOn.Pulse_1s && (Insp1_Y_RunCode == 1) || Insp1_Y_Wait;
            Insp1_Y_Work_BL = PulseOn.Pulse_1s && (Insp1_Y_RunCode == 2) || Insp1_Y_Work;

            Insp1_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.Insp1_Y.IsHomeAlready;
            #endregion
        }
        public void Insp2_YRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_Insp2_Y[0] = ParameterHelper.CurParam.Insp2_Y.Wait;
            Pos_Insp2_Y[1] = ParameterHelper.CurParam.Insp2_Y.Work;

            #endregion

            Insp2_Y_Stop = Insp2_Y_ToStop || Kernel.motion.Insp2_Y.AxisMotionIO.SVON == 0 || (!Insp2_Y_AllowMove && (Insp2_Y_RunCode > 0));
            Insp2_Y_ToStop = false;

            #region          
            if (Insp2_Y_Stop) { if (Kernel.motion.Insp2_Y.AxisMotionStatus.Stop == 0) { Kernel.motion.Insp2_Y.Stop(); } }
            if (Insp2_Y_HomeCondition) { if ((ManualMode && Insp2_Y_ToHome) || Insp2_Y_ToHome_A) { Insp2_Y_Homing = true; } }

            if (Insp2_Y_MoveCondition)
            {
                if ((ManualMode && Insp2_Y_ToWait) || Insp2_Y_ToWait_A) { if (!Insp2_Y_Wait) { Insp2_Y_RunCode = 1; } }
                if ((ManualMode && Insp2_Y_ToWork) || Insp2_Y_ToWork_A) { if (!Insp2_Y_Work) { Insp2_Y_RunCode = 2; } }

                Insp2_Y_Runing = Insp2_Y_RunCode > 0;
            }

            Insp2_Y_HomeCondition = Kernel.motion.Insp2_Y.AxisMotionIO.ALM == 0 && Kernel.motion.Insp2_Y.AxisMotionStatus.Stop == 1 && Insp2_Y_RunCode == 0 && !Insp2_Y_Homing && !Insp2_Y_Stop;
            Insp2_Y_MoveCondition = Insp2_Y_HomeCondition && Kernel.motion.Insp2_Y.IsHomeAlready && Kernel.motion.Insp2_Y.AxisMotionStatus.Stop == 1;

            if (Insp2_Y_Stop || Kernel.motion.Insp2_Y.AxisMotionIO.ALM == 1)
            {
                Insp2_Y_RunCode = 0;
            }

            acc = 0.5;
            dec = 0.5;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.Insp2_Y_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.Insp2_Y_Vel;
            AxisRun(Kernel.motion.Insp2_Y, ref Insp2_Y_Runing, Insp2_Y_RunCode, Pos_Insp2_Y, 1, speed_Y, acc, dec);

            if (Insp2_Y_Homing)
            {
                if (!Kernel.motion.Insp2_Y.IsHomeAlready)
                {
                    Kernel.motion.Insp2_Y.HomeStart = true;
                }
                Insp2_Y_Homing = false;
            }

            if (Kernel.motion.Insp2_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.Insp2_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.Insp2_Y.IsHomeAlready == true)
            {
                Insp2_Y_Wait = Kernel.motion.CheckINP(Kernel.motion.Insp2_Y.CurrentActPos, Pos_Insp2_Y[0], 0.002);
                Insp2_Y_Work = Kernel.motion.CheckINP(Kernel.motion.Insp2_Y.CurrentActPos, Pos_Insp2_Y[1], 0.002);

                if (Insp2_Y_Wait
                 || Insp2_Y_Work)
                {
                    Insp2_Y_RunCode = 0;
                }
            }
            else
            {
                Insp2_Y_Wait = false;
                Insp2_Y_Work = false;
            }

            if (Kernel.motion.Insp2_Y.AxisMotionIO.SVON == 0 || Kernel.motion.Insp2_Y.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.Insp2_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            Insp2_Y_ToHome = false;
            Insp2_Y_ToWait = false;
            Insp2_Y_ToWork = false;
            #endregion

            #region 状态刷新  
            Insp2_Y_Wait_BL = PulseOn.Pulse_1s && (Insp2_Y_RunCode == 1) || Insp2_Y_Wait;
            Insp2_Y_Work_BL = PulseOn.Pulse_1s && (Insp2_Y_RunCode == 2) || Insp2_Y_Work;

            Insp2_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.Insp2_Y.IsHomeAlready;
            #endregion
        }
        public void Insp3_YRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_Insp3_Y[0] = ParameterHelper.CurParam.Insp3_Y.Wait;
            Pos_Insp3_Y[1] = ParameterHelper.CurParam.Insp3_Y.Work;

            #endregion

            Insp3_Y_Stop = Insp3_Y_ToStop || Kernel.motion.Insp3_Y.AxisMotionIO.SVON == 0 || (!Insp3_Y_AllowMove && (Insp3_Y_RunCode > 0));
            Insp3_Y_ToStop = false;

            #region          
            if (Insp3_Y_Stop) { if (Kernel.motion.Insp3_Y.AxisMotionStatus.Stop == 0) { Kernel.motion.Insp3_Y.Stop(); } }
            if (Insp3_Y_HomeCondition) { if ((ManualMode && Insp1_Y_ToHome) || Insp3_Y_ToHome_A) { Insp3_Y_Homing = true; } }

            if (Insp3_Y_MoveCondition)
            {
                if ((ManualMode && Insp3_Y_ToWait) || Insp3_Y_ToWait_A) { if (!Insp3_Y_Wait) { Insp3_Y_RunCode = 1; } }
                if ((ManualMode && Insp3_Y_ToWork) || Insp3_Y_ToWork_A) { if (!Insp3_Y_Work) { Insp3_Y_RunCode = 2; } }

                Insp3_Y_Runing = Insp3_Y_RunCode > 0;
            }

            Insp3_Y_HomeCondition = Kernel.motion.Insp3_Y.AxisMotionIO.ALM == 0 && Kernel.motion.Insp3_Y.AxisMotionStatus.Stop == 1 && Insp3_Y_RunCode == 0 && !Insp3_Y_Homing && !Insp3_Y_Stop;
            Insp3_Y_MoveCondition = Insp3_Y_HomeCondition && Kernel.motion.Insp3_Y.IsHomeAlready && Kernel.motion.Insp3_Y.AxisMotionStatus.Stop == 1;

            if (Insp3_Y_Stop || Kernel.motion.Insp3_Y.AxisMotionIO.ALM == 1)
            {
                Insp3_Y_RunCode = 0;
            }

            acc = 0.5;
            dec = 0.5;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.Insp3_Y_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.Insp3_Y_Vel;
            AxisRun(Kernel.motion.Insp3_Y, ref Insp3_Y_Runing, Insp3_Y_RunCode, Pos_Insp3_Y, 1, speed_Y, acc, dec);

            if (Insp3_Y_Homing)
            {
                if (!Kernel.motion.Insp3_Y.IsHomeAlready)
                {
                    Kernel.motion.Insp3_Y.HomeStart = true;
                }
                Insp3_Y_Homing = false;
            }

            if (Kernel.motion.Insp3_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.Insp3_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.Insp3_Y.IsHomeAlready == true)
            {
                Insp3_Y_Wait = Kernel.motion.CheckINP(Kernel.motion.Insp3_Y.CurrentActPos, Pos_Insp3_Y[0], 0.002);
                Insp3_Y_Work = Kernel.motion.CheckINP(Kernel.motion.Insp3_Y.CurrentActPos, Pos_Insp3_Y[1], 0.002);

                if (Insp3_Y_Wait
                 || Insp3_Y_Work)
                {
                    Insp3_Y_RunCode = 0;
                }
            }
            else
            {
                Insp3_Y_Wait = false;
                Insp3_Y_Work = false;
            }

            if (Kernel.motion.Insp3_Y.AxisMotionIO.SVON == 0 || Kernel.motion.Insp3_Y.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.Insp3_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            Insp3_Y_ToHome = false;
            Insp3_Y_ToWait = false;
            Insp3_Y_ToWork = false;
            #endregion

            #region 状态刷新  
            Insp3_Y_Wait_BL = PulseOn.Pulse_1s && (Insp3_Y_RunCode == 1) || Insp3_Y_Wait;
            Insp3_Y_Work_BL = PulseOn.Pulse_1s && (Insp3_Y_RunCode == 2) || Insp3_Y_Work;

            Insp3_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.Insp3_Y.IsHomeAlready;
            #endregion
        }
        public void Insp4_YRun()
        {
            double acc = 0.1;
            double dec = 0.1;

            #region 位置更新
            Pos_Insp4_Y[0] = ParameterHelper.CurParam.Insp4_Y.Wait;
            Pos_Insp4_Y[1] = ParameterHelper.CurParam.Insp4_Y.Work;

            #endregion

            Insp4_Y_Stop = Insp4_Y_ToStop || Kernel.motion.Insp4_Y.AxisMotionIO.SVON == 0 || (!Insp4_Y_AllowMove && (Insp4_Y_RunCode > 0));
            Insp4_Y_ToStop = false;

            #region          
            if (Insp4_Y_Stop) { if (Kernel.motion.Insp4_Y.AxisMotionStatus.Stop == 0) { Kernel.motion.Insp4_Y.Stop(); } }
            if (Insp4_Y_HomeCondition) { if ((ManualMode && Insp4_Y_ToHome) || Insp4_Y_ToHome_A) { Insp4_Y_Homing = true; } }

            if (Insp4_Y_MoveCondition)
            {
                if ((ManualMode && Insp4_Y_ToWait) || Insp4_Y_ToWait_A) { if (!Insp4_Y_Wait) { Insp4_Y_RunCode = 1; } }
                if ((ManualMode && Insp4_Y_ToWork) || Insp4_Y_ToWork_A) { if (!Insp4_Y_Work) { Insp4_Y_RunCode = 2; } }

                Insp4_Y_Runing = Insp4_Y_RunCode > 0;
            }

            Insp4_Y_HomeCondition = Kernel.motion.Insp4_Y.AxisMotionIO.ALM == 0 && Kernel.motion.Insp4_Y.AxisMotionStatus.Stop == 1 && Insp4_Y_RunCode == 0 && !Insp4_Y_Homing && !Insp4_Y_Stop;
            Insp4_Y_MoveCondition = Insp4_Y_HomeCondition && Kernel.motion.Insp4_Y.IsHomeAlready && Kernel.motion.Insp4_Y.AxisMotionStatus.Stop == 1;

            if (Insp4_Y_Stop || Kernel.motion.Insp4_Y.AxisMotionIO.ALM == 1)
            {
                Insp4_Y_RunCode = 0;
            }

            acc = 0.5;
            dec = 0.5;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.Insp4_Y_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.Insp4_Y_Vel;
            AxisRun(Kernel.motion.Insp4_Y, ref Insp4_Y_Runing, Insp4_Y_RunCode, Pos_Insp4_Y, 1, speed_Y, acc, dec);

            if (Insp4_Y_Homing)
            {
                if (!Kernel.motion.Insp4_Y.IsHomeAlready)
                {
                    Kernel.motion.Insp4_Y.HomeStart = true;
                }
                Insp4_Y_Homing = false;
            }

            if (Kernel.motion.Insp4_Y.AxisMotionStatus.Stop == 1 && Kernel.motion.Insp4_Y.axis.State == Advantech.Motion.AxisState.STA_AX_READY && Kernel.motion.Insp4_Y.IsHomeAlready == true)
            {
                Insp4_Y_Wait = Kernel.motion.CheckINP(Kernel.motion.Insp4_Y.CurrentActPos, Pos_Insp4_Y[0], 0.002);
                Insp4_Y_Work = Kernel.motion.CheckINP(Kernel.motion.Insp4_Y.CurrentActPos, Pos_Insp4_Y[1], 0.002);

                if (Insp4_Y_Wait
                 || Insp4_Y_Work)
                {
                    Insp4_Y_RunCode = 0;
                }
            }
            else
            {
                Insp4_Y_Wait = false;
                Insp4_Y_Work = false;
            }

            if (Kernel.motion.Insp4_Y.AxisMotionIO.SVON == 0 || Kernel.motion.Insp4_Y.AxisMotionIO.ALM == 1)
            {
                Kernel.motion.Insp4_Y.IsHomeAlready = false;
            }
            #endregion

            #region 手动操作复位
            Insp4_Y_ToHome = false;
            Insp4_Y_ToWait = false;
            Insp4_Y_ToWork = false;
            #endregion

            #region 状态刷新  
            Insp4_Y_Wait_BL = PulseOn.Pulse_1s && (Insp4_Y_RunCode == 1) || Insp4_Y_Wait;
            Insp4_Y_Work_BL = PulseOn.Pulse_1s && (Insp4_Y_RunCode == 2) || Insp4_Y_Work;

            Insp4_Y_Homed_BL = PulseOn.Pulse_1s || Kernel.motion.Insp4_Y.IsHomeAlready;
            #endregion
        }
        public void EntryCV1_Run()
        {
            double acc = 0.1;
            double dec = 0.1;
            double[] Destination = new double[1] { 1000000 };

            CV1_Stop = (ManualMode && CV1_ToStop)|| CV1_ToStop_A || Kernel.motion.CV1_Driver.AxisMotionIO.SVON == 0 || Kernel.motion.CV1_Driver.AxisMotionIO.SVON ==0 ;
            CV1_ToStop = false;

            #region          
            if (CV1_Stop)
            {
                if (Kernel.motion.CV1_Driver.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.CV1_Driver.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.CV1_Driver);
                }              
            }

            if (Kernel.motion.CV1_Driver.AxisMotionStatus.Stop == 1 && Kernel.motion.CV1_Driver.AxisMotionStatus.Stop == 1)
            {
                if ((ManualMode && CV1_ToRun) || CV1_ToRun_A)
                {
                    CV1_Run = true;                   
                }
            }

            if (CV1_Stop || Kernel.motion.CV1_Driver.AxisMotionIO.ALM == 1)
            {
                CV1_Run = false;
            }
            acc = 1;
            dec = 1;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CV1_Driver_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CV1_Driver_Vel;
            AxisRun(Kernel.motion.CV1_Driver, ref CV1_Run, 21, Destination, 1, speed_Y, acc, dec);
         
            #endregion

            #region 手动操作复位
            CV1_ToRun = false;
            CV1_ToStop = false;
            #endregion

            #region 状态刷新  
            CV1_Run_BL = Kernel.motion.CV1_Driver.AxisMotionStatus.Stop == 0;
            CV1_Stop_BL = !CV1_Run_BL;
            #endregion
        }
        public void EntryCV2_Run()
        {
            double acc = 0.1;
            double dec = 0.1;
            double[] Destination = new double[1] { 1000000 };

            CV2_Stop = (ManualMode && CV2_ToStop)|| CV2_ToStop_A || Kernel.motion.CV2_Driver.AxisMotionIO.SVON == 0 || Kernel.motion.CV2_Driver.AxisMotionIO.SVON == 0;
            CV2_ToStop = false;

            #region          
            if (CV2_Stop)
            {
                if (Kernel.motion.CV2_Driver.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.CV2_Driver.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.CV2_Driver);
                }
            }

            if (Kernel.motion.CV2_Driver.AxisMotionStatus.Stop == 1 && Kernel.motion.CV2_Driver.AxisMotionStatus.Stop == 1)
            {
                if ((ManualMode && CV2_ToRun) || CV2_ToRun_A)
                {
                    CV2_Run = true;
                }
            }

            if (CV2_Stop || Kernel.motion.CV2_Driver.AxisMotionIO.ALM == 1)
            {
                CV2_Run = false;
            }
            acc = 1;
            dec = 1;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.CV2_Driver_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.CV2_Driver_Vel;
            AxisRun(Kernel.motion.CV2_Driver, ref CV2_Run, 21, Destination, 1, speed_Y, acc, dec);

            #endregion

            #region 手动操作复位
            CV2_ToRun = false;
            CV2_ToStop = false;
            #endregion

            #region 状态刷新  
            CV2_Run_BL = Kernel.motion.CV2_Driver.AxisMotionStatus.Stop == 0;
            CV2_Stop_BL = !CV2_Run_BL;
            #endregion
        }
        public void Insp1_CV_Run()
        {
            double acc = 0.1;
            double dec = 0.1;
            double[] Destination = new double[1] { 1000000 };

            Insp1CV_Stop = (ManualMode && Insp1CV_ToStop)|| Insp1CV_ToStop_A || Kernel.motion.Insp1_CV1.AxisMotionIO.SVON == 0 || Kernel.motion.Insp1_CV2.AxisMotionIO.SVON == 0;
            Insp1CV_ToStop = false;

            #region          
            if (Insp1CV_Stop)
            {
                if (Kernel.motion.Insp1_CV1.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.Insp1_CV1.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.Insp1_CV1);
                }
                if (Kernel.motion.Insp1_CV2.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.Insp1_CV2.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.Insp1_CV2);
                }
            }

            if (Kernel.motion.Insp1_CV1.AxisMotionStatus.Stop == 1&& Kernel.motion.Insp1_CV2.AxisMotionStatus.Stop == 1)
            {
                if ((ManualMode && Insp1CV_ToRun) || Insp1CV_ToRun_A)
                {
                    Insp1CV_Run = true;
                    Insp1CV2_Run = true;
                }
            }

            if (Insp1CV_Stop || Kernel.motion.Insp1_CV1.AxisMotionIO.ALM == 1)
            {
                Insp1CV_Run = false;
            }
            if (Insp1CV_Stop || Kernel.motion.Insp1_CV2.AxisMotionIO.ALM == 1)
            {
                Insp1CV2_Run = false;
            }

            acc = 0.1;
            dec = 0.1;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.Insp1_CV_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.Insp1_CV_Vel;
            AxisRun(Kernel.motion.Insp1_CV1, ref Insp1CV_Run, 21, Destination, 1, speed_Y, acc, dec);
            AxisRun(Kernel.motion.Insp1_CV2, ref Insp1CV2_Run, 21, Destination, 1, speed_Y, acc, dec);

            #endregion

            #region 手动操作复位
            Insp1CV_ToRun = false;
            Insp1CV_ToStop = false;
            #endregion

            #region 状态刷新  
            Insp1CV_Run_BL = Kernel.motion.Insp1_CV2.AxisMotionStatus.Stop == 0;
            Insp1CV_Stop_BL = !Insp1CV_Run_BL;
            #endregion
        }
        public void Insp2_CV_Run()
        {
            double acc = 0.1;
            double dec = 0.1;
            double[] Destination = new double[1] { 1000000 };

            Insp2CV_Stop = (ManualMode && Insp2CV_ToStop)|| Insp2CV_ToStop_A || Kernel.motion.Insp2_CV1.AxisMotionIO.SVON == 0 || Kernel.motion.Insp2_CV2.AxisMotionIO.SVON == 0;
            Insp2CV_ToStop = false;

            #region          
            if (Insp2CV_Stop)
            {
                if (Kernel.motion.Insp2_CV1.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.Insp2_CV1.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.Insp2_CV1);

                }
                if (Kernel.motion.Insp2_CV2.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.Insp2_CV2.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.Insp2_CV2);
                }
            }

            if (Kernel.motion.Insp2_CV1.AxisMotionStatus.Stop == 1&& Kernel.motion.Insp2_CV2.AxisMotionStatus.Stop == 1)
            {
                if ((ManualMode && Insp2CV_ToRun) || Insp2CV_ToRun_A)
                {
                    Insp2CV_Run = true;
                    Insp2CV2_Run = true;
                }
            }

            if (Insp2CV_Stop || Kernel.motion.Insp2_CV1.AxisMotionIO.ALM == 1)
            {
                Insp2CV_Run = false;
            }
            if (Insp2CV_Stop || Kernel.motion.Insp2_CV2.AxisMotionIO.ALM == 1)
            {
                Insp2CV2_Run = false;
            }

            acc = 0.1;
            dec = 0.1;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.Insp2_CV_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.Insp2_CV_Vel;
            AxisRun(Kernel.motion.Insp2_CV1, ref Insp2CV_Run, 21, Destination, 1, speed_Y, acc, dec);
            AxisRun(Kernel.motion.Insp2_CV2, ref Insp2CV2_Run, 21, Destination, 1, speed_Y, acc, dec);

            #endregion

            #region 手动操作复位
            Insp2CV_ToRun = false;
            Insp2CV_ToStop = false;
            #endregion

            #region 状态刷新  
            Insp2CV_Run_BL = Kernel.motion.Insp2_CV2.AxisMotionStatus.Stop == 0;
            Insp2CV_Stop_BL = !Insp2CV_Run_BL;
            #endregion
        }
        public void Insp3_CV_Run()
        {
            double acc = 0.1;
            double dec = 0.1;
            double[] Destination = new double[1] { 1000000 };

            Insp3CV_Stop = (ManualMode && Insp3CV_ToStop)|| Insp3CV_ToStop_A || Kernel.motion.Insp3_CV1.AxisMotionIO.SVON == 0 || Kernel.motion.Insp3_CV2.AxisMotionIO.SVON == 0;
            Insp3CV_ToStop = false;

            #region          
            if (Insp3CV_Stop)
            {
                if (Kernel.motion.Insp3_CV1.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.Insp3_CV1.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.Insp3_CV1);
                }
                if (Kernel.motion.Insp3_CV2.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.Insp3_CV2.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.Insp3_CV2);
                }
            }

            if (Kernel.motion.Insp3_CV1.AxisMotionStatus.Stop == 1 && Kernel.motion.Insp3_CV2.AxisMotionStatus.Stop == 1)
            {
                if ((ManualMode && Insp3CV_ToRun) || Insp3CV_ToRun_A)
                {
                    Insp3CV_Run = true;
                    Insp3CV2_Run = true;
                }
            }

            if (Insp3CV_Stop || Kernel.motion.Insp3_CV1.AxisMotionIO.ALM == 1)
            {
                Insp3CV_Run = false;
            }
            if (Insp3CV_Stop || Kernel.motion.Insp3_CV2.AxisMotionIO.ALM == 1)
            {
                Insp3CV2_Run = false;
            }

            acc = 0.5;
            dec = 0.5;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.Insp3_CV_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.Insp3_CV_Vel;
            AxisRun(Kernel.motion.Insp3_CV1, ref Insp3CV_Run, 21, Destination, 1, speed_Y, acc, dec);
            AxisRun(Kernel.motion.Insp3_CV2, ref Insp3CV2_Run, 21, Destination, 1, speed_Y, acc, dec);

            #endregion

            #region 手动操作复位
            Insp3CV_ToRun = false;
            Insp3CV_ToStop = false;
            #endregion

            #region 状态刷新  
            Insp3CV_Run_BL = Kernel.motion.Insp3_CV2.AxisMotionStatus.Stop == 0;
            Insp3CV_Stop_BL = !Insp3CV_Run_BL;
            #endregion
        }
        public void Insp4_CV_Run()
        {
            double acc = 0.1;
            double dec = 0.1;
            double[] Destination = new double[1] { 1000000 };

            Insp4CV_Stop = (ManualMode && Insp4CV_ToStop)|| Insp4CV_ToStop_A|| Kernel.motion.Insp4_CV1.AxisMotionIO.SVON == 0 || Kernel.motion.Insp4_CV2.AxisMotionIO.SVON == 0;
            Insp4CV_ToStop = false;

            #region          
            if (Insp4CV_Stop)
            {
                if (Kernel.motion.Insp4_CV1.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.Insp4_CV1.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.Insp4_CV1);
                }
                if (Kernel.motion.Insp4_CV2.AxisMotionStatus.Stop == 0)
                {
                    Kernel.motion.Insp4_CV2.Stop();
                    Kernel.motion.ResetCounters(Kernel.motion.Insp4_CV2);
                }
            }

            if (Kernel.motion.Insp4_CV1.AxisMotionStatus.Stop == 1 && Kernel.motion.Insp4_CV2.AxisMotionStatus.Stop == 1)
            {
                if ((ManualMode && Insp4CV_ToRun) || Insp4CV_ToRun_A)
                {
                    Insp4CV_Run = true;
                    Insp4CV2_Run = true;
                }
            }

            if (Insp4CV_Stop || Kernel.motion.Insp4_CV1.AxisMotionIO.ALM == 1)
            {
                Insp4CV_Run = false;
            }
            if (Insp4CV_Stop || Kernel.motion.Insp4_CV2.AxisMotionIO.ALM == 1)
            {
                Insp4CV2_Run = false;
            }

            acc = 0.5;
            dec = 0.5;
            double speed_Y = (ManualMode && ParameterHelper.SysParam.EQ.Speed.Insp4_CV_Vel > 50) ? 50 : ParameterHelper.SysParam.EQ.Speed.Insp4_CV_Vel;
            AxisRun(Kernel.motion.Insp4_CV1, ref Insp4CV_Run, 21, Destination, 1, speed_Y, acc, dec);
            AxisRun(Kernel.motion.Insp4_CV2, ref Insp4CV2_Run, 21, Destination, 1, speed_Y, acc, dec);

            #endregion

            #region 手动操作复位
            Insp4CV_ToRun = false;
            Insp4CV_ToStop = false;
            #endregion

            #region 状态刷新  
            Insp4CV_Run_BL = Kernel.motion.Insp4_CV2.AxisMotionStatus.Stop == 0;
            Insp4CV_Stop_BL = !Insp4CV_Run_BL;
            #endregion
        }
        public void RM_Insp1_ZCtr()
        {
            if (Insp1_RM_Z_ToWork)
            {
                Insp1_RM_Z_ToWork = false;
                if (Kernel.motion.Rm_Insp1_Z.Start_2 == 0)
                {
                    Kernel.motion.Rm_Insp1_Z.Start_1 = 1;
                }
            }
            if (Insp1_RM_Z_ToWait)
            {
                Insp1_RM_Z_ToWait = false;
                if (Kernel.motion.Rm_Insp1_Z.Start_0 == 0)
                {
                    Kernel.motion.Rm_Insp1_Z.Start_0 = 1;
                }
            }

            if (Insp1_RM_Z_RstForce)
            {
                Insp1_RM_Z_RstForce = false;
                Kernel.motion.Rm_Insp1_Z.Reset_force = 1;
            }
            Insp1_RM_Z_Wait = Kernel.motion.Rm_Insp1_Z.Start_0 == 1;
            Insp1_RM_Z_Work = Kernel.motion.Rm_Insp1_Z.Start_2 == 1;

            Insp1_RM_Z_Wait_BL = Insp1_RM_Z_Wait;
            Insp1_RM_Z_Work_BL = Insp1_RM_Z_Work;
        }
        public void RM_Insp2_ZCtr()
        {
            if (Insp2_RM_Z_ToWork)
            {
                Insp2_RM_Z_ToWork = false;
                if (Kernel.motion.Rm_Insp2_Z.Start_2 == 0)
                {
                    Kernel.motion.Rm_Insp2_Z.Start_1 = 1;
                }
            }
            if (Insp2_RM_Z_ToWait)
            {
                Insp2_RM_Z_ToWait = false;
                if (Kernel.motion.Rm_Insp2_Z.Start_0 == 0)
                {
                    Kernel.motion.Rm_Insp2_Z.Start_0 = 1;
                }
            }

            if (Insp2_RM_Z_RstForce)
            {
                Insp2_RM_Z_RstForce = false;
                Kernel.motion.Rm_Insp2_Z.Reset_force = 1;
            }

            Insp2_RM_Z_Wait = Kernel.motion.Rm_Insp2_Z.Start_0 == 1;
            Insp2_RM_Z_Work = Kernel.motion.Rm_Insp2_Z.Start_2 == 1;

            Insp2_RM_Z_Wait_BL = Insp2_RM_Z_Wait;
            Insp2_RM_Z_Work_BL = Insp2_RM_Z_Work;
        }
        public void RM_Insp3_ZCtr()
        {
            if (Insp3_RM_Z_ToWork)
            {
                Insp3_RM_Z_ToWork = false;
                if (Kernel.motion.Rm_Insp3_Z.Start_2 == 0)
                {
                    Kernel.motion.Rm_Insp3_Z.Start_1 = 1;
                }
            }
            if (Insp3_RM_Z_ToWait)
            {
                Insp3_RM_Z_ToWait = false;
                if (Kernel.motion.Rm_Insp3_Z.Start_0 == 0)
                {
                    Kernel.motion.Rm_Insp3_Z.Start_0 = 1;
                }
            }

            if (Insp3_RM_Z_RstForce)
            {
                Insp3_RM_Z_RstForce = false;
                Kernel.motion.Rm_Insp3_Z.Reset_force = 1;
            }

            Insp3_RM_Z_Wait = Kernel.motion.Rm_Insp3_Z.Start_0 == 1;
            Insp3_RM_Z_Work = Kernel.motion.Rm_Insp3_Z.Start_2 == 1;

            Insp3_RM_Z_Wait_BL = Insp3_RM_Z_Wait;
            Insp3_RM_Z_Work_BL = Insp3_RM_Z_Work;
        }
        public void RM_Insp4_ZCtr()
        {
            if (Insp4_RM_Z_ToWork)
            {
                Insp4_RM_Z_ToWork = false;
                if (Kernel.motion.Rm_Insp4_Z.Start_2 == 0)
                {
                    Kernel.motion.Rm_Insp4_Z.Start_1 = 1;
                }
            }
            if (Insp4_RM_Z_ToWait)
            {
                Insp4_RM_Z_ToWait = false;
                if (Kernel.motion.Rm_Insp4_Z.Start_0 == 0)
                {
                    Kernel.motion.Rm_Insp4_Z.Start_0 = 1;
                }
            }

            if (Insp4_RM_Z_RstForce)
            {
                Insp4_RM_Z_RstForce = false;
                Kernel.motion.Rm_Insp4_Z.Reset_force = 1;
            }

            Insp4_RM_Z_Wait = Kernel.motion.Rm_Insp4_Z.Start_0 == 1;
            Insp4_RM_Z_Work = Kernel.motion.Rm_Insp4_Z.Start_2 == 1;            

            Insp1_RM_Z_Wait_BL = Insp4_RM_Z_Wait;
            Insp1_RM_Z_Work_BL = Insp4_RM_Z_Work;
        }

        public void OP_Auto()
        {
            #region CV1_TrackSW_Y
            CV1_TrackSW_Y_ToHome_A = !CV1_TrackSW_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            CV1_TrackSW_Y_LDPt1_A = !CV1_TrackSW_Y_LDPt1 && (CV1StatusCode == LDCVStatus.Y_ToLoadPort1);
            CV1_TrackSW_Y_LDPt2_A = !CV1_TrackSW_Y_LDPt2 && (CV1StatusCode == LDCVStatus.Y_ToLoadPort2);
            CV1_TrackSW_Y_ToInsp1_A = !CV1_TrackSW_Y_Insp1 && (CV1StatusCode == LDCVStatus.Y_ToInsp1 || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            CV1_TrackSW_Y_ToInsp2_A = !CV1_TrackSW_Y_Insp2 && (CV1StatusCode == LDCVStatus.Y_ToInsp2);
            #endregion
            #region CV2_TrackSW_Y
            CV2_TrackSW_Y_ToHome_A = !CV2_TrackSW_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            CV2_TrackSW_Y_LDPt1_A = !CV2_TrackSW_Y_LDPt1 && (CV2StatusCode == LDCVStatus.Y_ToLoadPort1);
            CV2_TrackSW_Y_LDPt2_A = !CV2_TrackSW_Y_LDPt2 && (CV2StatusCode == LDCVStatus.Y_ToLoadPort2);
            CV2_TrackSW_Y_ToInsp1_A = !CV2_TrackSW_Y_Insp1 && (CV2StatusCode == LDCVStatus.Y_ToInsp1 || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            CV2_TrackSW_Y_ToInsp2_A = !CV2_TrackSW_Y_Insp2 && (CV2StatusCode == LDCVStatus.Y_ToInsp2);
            #endregion
            #region CV1_Y
            CV1_Y_ToHome_A = !CV1_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            CV1_Y_ToWork_A = !CV1_Y_Work && (CV1StatusCode == LDCVStatus.CV_Y_ToWork);
            CV1_Y_ToWait_A = !CV1_Y_Wait && (CV1StatusCode == LDCVStatus.LoadPrepare || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            #endregion
            #region CV2_Y
            CV2_Y_ToHome_A = !CV2_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            CV2_Y_ToWork_A = !CV2_Y_Work && (CV2StatusCode == LDCVStatus.CV_Y_ToWork); ;
            CV2_Y_ToWait_A = !CV2_Y_Wait && (CV2StatusCode == LDCVStatus.LoadPrepare || ExcInitStatusCode == ExcInitStatus.InspST_ToWork); ;
            #endregion
            #region CCD1_X
            CCD1_X_ToHome_A = !CCD1_X_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            CCD1_X_ToCH1Mark_A = !CCD1_X_CH1Mark && (CCD1StatusCode == CCDStatus.ToCH1_Mark || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            CCD1_X_ToCH1Work_A = !CCD1_X_CH1Work && (CCD1StatusCode == CCDStatus.ToCH1_Insp_Idx);
            CCD1_X_ToCH2Mark_A = !CCD1_X_CH2Mark && (CCD1StatusCode == CCDStatus.ToCH2_Mark);
            CCD1_X_ToCH2Work_A = !CCD1_X_CH2Work && (CCD1StatusCode == CCDStatus.ToCH2_Insp_Idx);
            CCD1_X_ToWait_A = !CCD1_X_Wait && (CCD1StatusCode == CCDStatus.Ready);

            #endregion
            #region CCD1_Y
            CCD1_Y_ToHome_A = !CCD1_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            CCD1_Y_ToCH1Mark_A = !CCD1_Y_CH1Mark && (CCD1StatusCode == CCDStatus.ToCH1_Mark || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            CCD1_Y_ToCH1Work_A = !CCD1_Y_CH1Work && (CCD1StatusCode == CCDStatus.ToCH1_Insp_Idx);
            CCD1_Y_ToCH2Mark_A = !CCD1_Y_CH2Mark && (CCD1StatusCode == CCDStatus.ToCH2_Mark);
            CCD1_Y_ToCH2Work_A = !CCD1_Y_CH2Work && (CCD1StatusCode == CCDStatus.ToCH2_Insp_Idx);
            CCD1_Y_ToWait_A = !CCD1_Y_Wait && (CCD1StatusCode == CCDStatus.Ready);

            #endregion
            #region CCD1_Z
            CCD1_Z_ToHome_A = !CCD1_Z_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_1fst);
            CCD1_Z_ToCH1Mark_A = !CCD1_Z_CH1Mark && (CCD1StatusCode == CCDStatus.ToCH1_Mark);
            CCD1_Z_ToCH1Work_A = !CCD1_Z_CH1Work && (CCD1StatusCode == CCDStatus.ToCH1_Insp_Idx);
            CCD1_Z_ToCH2Mark_A = !CCD1_Z_CH2Mark && (CCD1StatusCode == CCDStatus.ToCH2_Mark);
            CCD1_Z_ToCH2Work_A = !CCD1_Z_CH2Work && (CCD1StatusCode == CCDStatus.ToCH2_Insp_Idx);
            CCD1_Z_ToWait_A = !CCD1_Z_Wait && (CCD1StatusCode == CCDStatus.Ready);

            #endregion
            #region CCD2_X
            CCD2_X_ToHome_A = !CCD2_X_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            CCD2_X_ToCH1Mark_A = !CCD2_X_CH1Mark && (CCD2StatusCode == CCDStatus.ToCH1_Mark || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            CCD2_X_ToCH1Work_A = !CCD2_X_CH1Work && (CCD2StatusCode == CCDStatus.ToCH1_Insp_Idx);
            CCD2_X_ToCH2Mark_A = !CCD2_X_CH2Mark && (CCD2StatusCode == CCDStatus.ToCH2_Mark);
            CCD2_X_ToCH2Work_A = !CCD2_X_CH2Work && (CCD2StatusCode == CCDStatus.ToCH2_Insp_Idx);
            CCD2_X_ToWait_A = !CCD2_X_Wait && (CCD2StatusCode == CCDStatus.Ready);

            #endregion
            #region CCD2_Y
            CCD2_Y_ToHome_A = !CCD2_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            CCD2_Y_ToCH1Mark_A = !CCD2_Y_CH1Mark && (CCD2StatusCode == CCDStatus.ToCH1_Mark || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            CCD2_Y_ToCH1Work_A = !CCD2_Y_CH1Work && (CCD2StatusCode == CCDStatus.ToCH1_Insp_Idx);
            CCD2_Y_ToCH2Mark_A = !CCD2_Y_CH2Mark && (CCD2StatusCode == CCDStatus.ToCH2_Mark);
            CCD2_Y_ToCH2Work_A = !CCD2_Y_CH2Work && (CCD2StatusCode == CCDStatus.ToCH2_Insp_Idx);
            CCD2_Y_ToWait_A = !CCD2_Y_Wait && (CCD2StatusCode == CCDStatus.Ready);

            #endregion
            #region CCD2_Z
            CCD2_Z_ToHome_A = !CCD2_Z_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_1fst);
            CCD2_Z_ToCH1Mark_A = !CCD2_Z_CH1Mark && (CCD2StatusCode == CCDStatus.ToCH1_Mark);
            CCD2_Z_ToCH1Work_A = !CCD2_Z_CH1Work && (CCD2StatusCode == CCDStatus.ToCH1_Insp_Idx);
            CCD2_Z_ToCH2Mark_A = !CCD2_Z_CH2Mark && (CCD2StatusCode == CCDStatus.ToCH2_Mark);
            CCD2_Z_ToCH2Work_A = !CCD2_Z_CH2Work && (CCD2StatusCode == CCDStatus.ToCH2_Insp_Idx);
            CCD2_Z_ToWait_A = !CCD2_Z_Wait && (CCD2StatusCode == CCDStatus.Ready);

            #endregion
            #region Insp1_Y
            Insp1_Y_ToHome_A = !Insp1_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            Insp1_Y_ToWork_A = !Insp1_Y_Work && (Insp1StatusCode == InspStatus.LoadPrepare || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            //Insp1_Y_ToWait_A = !Insp1_Y_Wait  && (Insp1StatusCode == InspStatus.InspCompleted);
            #endregion
            #region Insp2_Y
            Insp2_Y_ToHome_A = !Insp2_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            Insp2_Y_ToWork_A = !Insp2_Y_Work && (Insp2StatusCode == InspStatus.LoadPrepare || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            //Insp2_Y_ToWait_A = !Insp2_Y_Wait  && (ExcInitStatusCode == ExcInitStatus.ExcTR_X_ToFlip);
            #endregion
            #region Insp3_Y
            Insp3_Y_ToHome_A = !Insp3_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            Insp3_Y_ToWork_A = !Insp3_Y_Work && (Insp3StatusCode == InspStatus.LoadPrepare || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            //Insp3_Y_ToWait_A = !Insp3_Y_Wait  && (ExcInitStatusCode == ExcInitStatus.ExcTR_X_ToFlip);
            #endregion
            #region Insp4_Y
            Insp4_Y_ToHome_A = !Insp4_Y_Homed && (InitStatusCode == InitStatus.ToHome || ExcInitStatusCode == ExcInitStatus.ToHome_2nd);
            Insp4_Y_ToWork_A = !Insp4_Y_Work && (Insp4StatusCode == InspStatus.LoadPrepare || ExcInitStatusCode == ExcInitStatus.InspST_ToWork);
            //Insp4_Y_ToWait_A = !Insp4_Y_Wait  && (ExcInitStatusCode == ExcInitStatus.ExcTR_X_ToFlip);
            #endregion
            #region Insp1_RM_Z
            Insp1_RM_Z_ToHome_A = !Insp1_RM_Z_Homed && (InitStatusCode == InitStatus.ToHome);
            Insp1_RM_Z_ToWork_A = !Insp1_RM_Z_Work && (Insp1StatusCode == InspStatus.InspST_RM_ZToWork);
            Insp1_RM_Z_ToWait_A = !Insp1_RM_Z_Wait && (Insp1StatusCode == InspStatus.InspST_RM_ZToWait);
            #endregion
            #region Insp2_RM_Z
            Insp2_RM_Z_ToHome_A = !Insp2_RM_Z_Homed && (InitStatusCode == InitStatus.ToHome);
            Insp2_RM_Z_ToWork_A = !Insp2_RM_Z_Work && (Insp2StatusCode == InspStatus.InspST_RM_ZToWork);
            Insp2_RM_Z_ToWait_A = !Insp2_RM_Z_Wait && (Insp2StatusCode == InspStatus.InspST_RM_ZToWait);
            #endregion
            #region Insp3_RM_Z
            Insp3_RM_Z_ToHome_A = !Insp3_RM_Z_Homed && (InitStatusCode == InitStatus.ToHome);
            Insp3_RM_Z_ToWork_A = !Insp3_RM_Z_Work && (Insp3StatusCode == InspStatus.InspST_RM_ZToWork);
            Insp3_RM_Z_ToWait_A = !Insp3_RM_Z_Wait && (Insp3StatusCode == InspStatus.InspST_RM_ZToWait);
            #endregion
            #region Insp4_RM_Z
            Insp4_RM_Z_ToHome_A = !Insp4_RM_Z_Homed && (InitStatusCode == InitStatus.ToHome);
            Insp4_RM_Z_ToWork_A = !Insp4_RM_Z_Work && (Insp4StatusCode == InspStatus.InspST_RM_ZToWork);
            Insp4_RM_Z_ToWait_A = !Insp4_RM_Z_Wait && (Insp4StatusCode == InspStatus.InspST_RM_ZToWait);
            #endregion

            CV1_Cyl_ToUp_A = !CV1_Cyl_Up && (CV1StatusCode == LDCVStatus.LoadPrepare || CV1StatusCode == LDCVStatus.PinCylinder_ToUp_2st);
            CV1_Cyl_ToDn_A = !CV1_Cyl_Dn && (CV1StatusCode == LDCVStatus.PinCylinder_ToDown_1st || CV1StatusCode == LDCVStatus.PinCylinder_ToDown_2st);
            CV2_Cyl_ToUp_A = !CV2_Cyl_Up && (CV2StatusCode == LDCVStatus.LoadPrepare || CV2StatusCode == LDCVStatus.PinCylinder_ToUp_2st);
            CV2_Cyl_ToDn_A = !CV2_Cyl_Dn && (CV2StatusCode == LDCVStatus.PinCylinder_ToDown_1st || CV2StatusCode == LDCVStatus.PinCylinder_ToDown_2st);
            Insp1_Cyl_ToUp_A = !Insp1_Cyl_Up && (Insp1StatusCode == InspStatus.Load);
            Insp1_Cyl_ToDn_A = !Insp1_Cyl_Dn && (Insp1StatusCode == InspStatus.PinCylinder_ToDown);
            Insp2_Cyl_ToUp_A = !Insp2_Cyl_Up && (Insp2StatusCode == InspStatus.Load);
            Insp2_Cyl_ToDn_A = !Insp2_Cyl_Dn && (Insp2StatusCode == InspStatus.PinCylinder_ToDown);
            Insp3_Cyl_ToUp_A = !Insp3_Cyl_Up && (Insp3StatusCode == InspStatus.Load);
            Insp3_Cyl_ToDn_A = !Insp3_Cyl_Dn && (Insp3StatusCode == InspStatus.PinCylinder_ToDown);
            Insp4_Cyl_ToUp_A = !Insp4_Cyl_Up && (Insp4StatusCode == InspStatus.Load);
            Insp4_Cyl_ToDn_A = !Insp4_Cyl_Dn && (Insp4StatusCode == InspStatus.PinCylinder_ToDown);

            Insp1_ToVacOnn_A = !Insp1_ToVacOnn_A && (Insp1StatusCode == InspStatus.ST_VacOn);
            Insp1_ToVacOff_A = !Insp1_ToVacOff_A && (Insp1StatusCode == InspStatus.ST_VacOff);
            Insp2_ToVacOnn_A = !Insp2_ToVacOnn_A && (Insp2StatusCode == InspStatus.ST_VacOn);
            Insp2_ToVacOff_A = !Insp2_ToVacOff_A && (Insp2StatusCode == InspStatus.ST_VacOff);
            Insp3_ToVacOnn_A = !Insp3_ToVacOnn_A && (Insp3StatusCode == InspStatus.ST_VacOn);
            Insp3_ToVacOff_A = !Insp3_ToVacOff_A && (Insp3StatusCode == InspStatus.ST_VacOff);
            Insp4_ToVacOnn_A = !Insp4_ToVacOnn_A && (Insp4StatusCode == InspStatus.ST_VacOn);
            Insp4_ToVacOff_A = !Insp4_ToVacOff_A && (Insp4StatusCode == InspStatus.ST_VacOff);

            SafeDoor1_ToLockk_A = !SafeDoor1_Lockk && AutoMode;
            SafeDoor1_ToULock_A = !SafeDoor1_ULock && !AutoMode;

            SafeDoor2_ToLockk_A = !SafeDoor2_Lockk && AutoMode;
            SafeDoor2_ToULock_A = !SafeDoor2_ULock && !AutoMode;


            CV1_ToRun_A = !CV1_Run && (CV1StatusCode == LDCVStatus.CV_Run_1st || CV1StatusCode == LDCVStatus.CV_Run_2st || CV1StatusCode == LDCVStatus.SendOut_Insp1 || CV1StatusCode == LDCVStatus.SendOut_Insp2);
            CV1_ToStop_A = !CV1_Stop && (CV1StatusCode == LDCVStatus.LoadCompleted_1st || CV1StatusCode == LDCVStatus.LoadCompleted_2st || CV1StatusCode == LDCVStatus.SendCompleted_1st || CV1StatusCode == LDCVStatus.SendCompleted_2st);
            CV2_ToRun_A = !CV2_Run && (CV2StatusCode == LDCVStatus.CV_Run_1st || CV2StatusCode == LDCVStatus.CV_Run_2st || CV2StatusCode == LDCVStatus.SendOut_Insp1 || CV2StatusCode == LDCVStatus.SendOut_Insp2);
            CV2_ToStop_A = !CV2_Stop && (CV2StatusCode == LDCVStatus.LoadCompleted_1st || CV2StatusCode == LDCVStatus.LoadCompleted_2st || CV2StatusCode == LDCVStatus.SendCompleted_1st || CV2StatusCode == LDCVStatus.SendCompleted_2st);
            Insp1CV_ToRun_A = !Insp1CV_Run && (Insp1StatusCode == InspStatus.Receiving || Insp1StatusCode == InspStatus.SendOut);
            Insp1CV_ToStop_A = !Insp1CV_Stop && (Insp1StatusCode == InspStatus.RevCompleted || Insp1StatusCode == InspStatus.SendCompeted);
            Insp2CV_ToRun_A = !Insp2CV_Run && (Insp2StatusCode == InspStatus.Receiving || Insp2StatusCode == InspStatus.SendOut);
            Insp2CV_ToStop_A = !Insp2CV_Stop && (Insp2StatusCode == InspStatus.RevCompleted || Insp2StatusCode == InspStatus.SendCompeted);
            Insp3CV_ToRun_A = !Insp3CV_Run && (Insp3StatusCode == InspStatus.Receiving || Insp3StatusCode == InspStatus.SendOut);
            Insp3CV_ToStop_A = !Insp3CV_Stop && (Insp3StatusCode == InspStatus.RevCompleted || Insp3StatusCode == InspStatus.SendCompeted);
            Insp4CV_ToRun_A = !Insp4CV_Run && (Insp4StatusCode == InspStatus.Receiving || Insp4StatusCode == InspStatus.SendOut);
            Insp4CV_ToStop_A = !Insp4CV_Stop && (Insp4StatusCode == InspStatus.RevCompleted || Insp4StatusCode == InspStatus.SendCompeted);

            ToUp_CH1_Ready_A = !ToUp_CH1_Ready && (CV1StatusCode == LDCVStatus.LoadReq_1st);
            ToUp_CH1_Receiving_A = !ToUp_CH1_Receiving && (CV1StatusCode == LDCVStatus.CV_Run_1st);
            ToUp_CH2_Ready_A = !ToUp_CH2_Ready && (CV1StatusCode == LDCVStatus.LoadReq_2st);
            ToUp_CH2_Receiving_A = !ToUp_CH2_Receiving && (CV1StatusCode == LDCVStatus.CV_Run_2st);
            ToUp_CH3_Ready_A = !ToUp_CH3_Ready && (CV2StatusCode == LDCVStatus.LoadReq_1st);
            ToUp_CH3_Receiving_A = !ToUp_CH3_Receiving && (CV2StatusCode == LDCVStatus.CV_Run_1st);
            ToUp_CH4_Ready_A = !ToUp_CH4_Ready && (CV2StatusCode == LDCVStatus.LoadReq_2st);
            ToUp_CH4_Receiving_A = !ToUp_CH4_Receiving && (CV2StatusCode == LDCVStatus.CV_Run_2st);

            ToDn_CH1_Ready_A = !ToDn_CH1_Ready && (Insp1StatusCode == InspStatus.SendReady || Insp1StatusCode == InspStatus.SendOut );
            ToDn_CH2_Ready_A = !ToDn_CH2_Ready && (Insp2StatusCode == InspStatus.SendReady || Insp2StatusCode == InspStatus.SendOut);
            ToDn_CH3_Ready_A = !ToDn_CH3_Ready && (Insp3StatusCode == InspStatus.SendReady || Insp3StatusCode == InspStatus.SendOut);
            ToDn_CH4_Ready_A = !ToDn_CH4_Ready && (Insp4StatusCode == InspStatus.SendReady || Insp4StatusCode == InspStatus.SendOut);
            ToDn_CH1_Sending_A = !ToDn_CH1_Ready && (Insp1StatusCode == InspStatus.SendOut );
            ToDn_CH2_Sending_A = !ToDn_CH2_Ready && (Insp2StatusCode == InspStatus.SendOut);
            ToDn_CH3_Sending_A = !ToDn_CH3_Ready && (Insp3StatusCode == InspStatus.SendOut);
            ToDn_CH4_Sending_A = !ToDn_CH4_Ready && (Insp4StatusCode == InspStatus.SendOut);

            ToUp_CH1_Ready_Cancel_A = CV1StatusCode == LDCVStatus.LoadCompleted_1st||CV1StatusCode == LDCVStatus.Init;
            ToUp_CH2_Ready_Cancel_A = CV1StatusCode == LDCVStatus.LoadCompleted_2st || CV1StatusCode == LDCVStatus.Init;
            ToUp_CH3_Ready_Cancel_A = CV2StatusCode == LDCVStatus.LoadCompleted_1st || CV2StatusCode == LDCVStatus.Init;
            ToUp_CH4_Ready_Cancel_A = CV2StatusCode == LDCVStatus.LoadCompleted_2st || CV2StatusCode == LDCVStatus.Init;
            ToUp_CH1_Receiving_Cancel_A = CV1StatusCode == LDCVStatus.LoadCompleted_1st || CV1StatusCode == LDCVStatus.Init;
            ToUp_CH2_Receiving_Cancel_A = CV1StatusCode == LDCVStatus.LoadCompleted_2st || CV1StatusCode == LDCVStatus.Init;
            ToUp_CH3_Receiving_Cancel_A = CV2StatusCode == LDCVStatus.LoadCompleted_1st || CV2StatusCode == LDCVStatus.Init;
            ToUp_CH4_Receiving_Cancel_A = CV2StatusCode == LDCVStatus.LoadCompleted_2st || CV2StatusCode == LDCVStatus.Init;


            ToDn_CH1_Ready_Cancel_A = Insp1StatusCode == InspStatus.SendCompeted || Insp1StatusCode == InspStatus.Init;
            ToDn_CH2_Ready_Cancel_A = Insp2StatusCode == InspStatus.SendCompeted || Insp1StatusCode == InspStatus.Init;
            ToDn_CH3_Ready_Cancel_A = Insp3StatusCode == InspStatus.SendCompeted || Insp1StatusCode == InspStatus.Init;
            ToDn_CH4_Ready_Cancel_A = Insp4StatusCode == InspStatus.SendCompeted || Insp1StatusCode == InspStatus.Init;
            ToDn_CH1_Sending_Cancel_A = Insp1StatusCode == InspStatus.SendCompeted || Insp1StatusCode == InspStatus.Init;
            ToDn_CH2_Sending_Cancel_A = Insp2StatusCode == InspStatus.SendCompeted || Insp1StatusCode == InspStatus.Init;
            ToDn_CH3_Sending_Cancel_A = Insp3StatusCode == InspStatus.SendCompeted || Insp1StatusCode == InspStatus.Init;
            ToDn_CH4_Sending_Cancel_A = Insp4StatusCode == InspStatus.SendCompeted || Insp1StatusCode == InspStatus.Init;

            CodeRead1_A = !CodeRead1_Completed && (PulseOn.Pulse_500ms && (CV1StatusCode == LDCVStatus.CV_Run_1st||CV1StatusCode==LDCVStatus.CV_Run_2st)&&!DryRunMode);
            CodeRead2_A = !CodeRead2_Completed && (PulseOn.Pulse_500ms && (CV2StatusCode == LDCVStatus.CV_Run_1st||CV2StatusCode==LDCVStatus.CV_Run_2st)&&!DryRunMode);

        }

        bool UnloadFlag = false;
        bool RunFlag = false;
        int timecot1 = 0;
        public void DORun()
        {

            #region 真空

#if false


         
            LaserST4_ToVacOn_A = (ExcInitStatusCode == ExcInitStatus.VacConfirm && ParameterHelper.LaserST4.Enable && !LaserST4_Vac) || (LDTR1PutStatusCode == TRPutStatus.LaserST_VacOn || LDTR2PutStatusCode == TRPutStatus.LaserST_VacOn) && LaserST_R_LD4 && !DryRunMode;
            LaserST4_ToVacOff_A = (ULDTR1GetStatusCode == TRGetStatus.LaserST_VacOff || ULDTR2GetStatusCode == TRGetStatus.LaserST_VacOff) && LaserST_R_LD8;

            LaserST5_ToVacOn_A = (ExcInitStatusCode == ExcInitStatus.VacConfirm && ParameterHelper.LaserST5.Enable && !LaserST5_Vac) || (LDTR1PutStatusCode == TRPutStatus.LaserST_VacOn || LDTR2PutStatusCode == TRPutStatus.LaserST_VacOn) && LaserST_R_LD5 && !DryRunMode;
            LaserST5_ToVacOff_A = (ULDTR1GetStatusCode == TRGetStatus.LaserST_VacOff || ULDTR2GetStatusCode == TRGetStatus.LaserST_VacOff) && LaserST_R_LD1;

            LaserST6_ToVacOn_A = (ExcInitStatusCode == ExcInitStatus.VacConfirm && ParameterHelper.LaserST6.Enable && !LaserST6_Vac) || (LDTR1PutStatusCode == TRPutStatus.LaserST_VacOn || LDTR2PutStatusCode == TRPutStatus.LaserST_VacOn) && LaserST_R_LD6 && !DryRunMode;
            LaserST6_ToVacOff_A = (ULDTR1GetStatusCode == TRGetStatus.LaserST_VacOff || ULDTR2GetStatusCode == TRGetStatus.LaserST_VacOff) && LaserST_R_LD2;

            LaserST7_ToVacOn_A = (ExcInitStatusCode == ExcInitStatus.VacConfirm && ParameterHelper.LaserST7.Enable && !LaserST7_Vac) || (LDTR1PutStatusCode == TRPutStatus.LaserST_VacOn || LDTR2PutStatusCode == TRPutStatus.LaserST_VacOn) && LaserST_R_LD7 && !DryRunMode;
            LaserST7_ToVacOff_A = (ULDTR1GetStatusCode == TRGetStatus.LaserST_VacOff || ULDTR2GetStatusCode == TRGetStatus.LaserST_VacOff) && LaserST_R_LD3;

#endif

            #endregion

            #region 气缸

            //Door_ToLock = ProcedureHelper_EQ.Door_ToLock;
            //Door_ToUnlock = ProcedureHelper_EQ.Door_ToUnlock;
            Kernel.Exc.DO.Y05B_FourColor_Lamp_Y = (byte)((ManualMode) ? 1 : 0);
            Kernel.Exc.DO.Y05D_FourColor_Lamp_R = (byte)((Alarm) ? 1 : 0);
            Kernel.Exc.DO.Y05C_FourColor_Lamp_G = (byte)((AutoMode) ? 1 : 0);


            Kernel.Exc.DO.Y022_1_CV_Cyl_Up = (byte)(((ManualMode && CV1_Cyl_ToUp) || CV1_Cyl_ToUp_A) || (Kernel.Exc.DO.Y022_1_CV_Cyl_Up == 1 && !CV1_Cyl_ToDn && !CV1_Cyl_ToDn_A) ? 1 : 0);
            Kernel.Exc.DO.Y023_1_CV_Cyl_Dn = (byte)(((ManualMode && CV1_Cyl_ToDn) || CV1_Cyl_ToDn_A) || (Kernel.Exc.DO.Y023_1_CV_Cyl_Dn == 1 && !CV1_Cyl_ToUp && !CV1_Cyl_ToUp_A) ? 1 : 0);
            CV1_Cyl_ToUp = false;
            CV1_Cyl_ToDn = false;
            CV1_Cyl_Up_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y022_1_CV_Cyl_Up == 1) || CV1_Cyl_Up;
            CV1_Cyl_Dn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y023_1_CV_Cyl_Dn == 1) || CV1_Cyl_Dn;


            Kernel.Exc.DO.Y028_2_CV_Cyl_Up = (byte)(((ManualMode && CV2_Cyl_ToUp) || CV2_Cyl_ToUp_A) || (Kernel.Exc.DO.Y028_2_CV_Cyl_Up == 1 && !CV2_Cyl_ToDn && !CV2_Cyl_ToDn_A) ? 1 : 0);
            Kernel.Exc.DO.Y029_2_CV_Cyl_Dn = (byte)(((ManualMode && CV2_Cyl_ToDn) || CV2_Cyl_ToDn_A) || (Kernel.Exc.DO.Y029_2_CV_Cyl_Dn == 1 && !CV2_Cyl_ToUp && !CV2_Cyl_ToUp_A) ? 1 : 0);
            CV2_Cyl_ToUp = false;
            CV2_Cyl_ToDn = false;
            CV2_Cyl_Up_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y028_2_CV_Cyl_Up == 1) || CV2_Cyl_Up;
            CV2_Cyl_Dn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y029_2_CV_Cyl_Dn == 1) || CV2_Cyl_Dn;


            Kernel.Exc.DO.Y030_1_Insp_Cyl_Up = (byte)(((ManualMode && Insp1_Cyl_ToUp) || Insp1_Cyl_ToUp_A) || (Kernel.Exc.DO.Y030_1_Insp_Cyl_Up == 1 && !Insp1_Cyl_ToDn && !Insp1_Cyl_ToDn_A) ? 1 : 0);
            Kernel.Exc.DO.Y031_1_Insp_Cyl_Dn = (byte)(((ManualMode && Insp1_Cyl_ToDn) || Insp1_Cyl_ToDn_A) || (Kernel.Exc.DO.Y031_1_Insp_Cyl_Dn == 1 && !Insp1_Cyl_ToUp && !Insp1_Cyl_ToUp_A) ? 1 : 0);
            Insp1_Cyl_ToUp = false;
            Insp1_Cyl_ToDn = false;
            Insp1_Cyl_Up_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y030_1_Insp_Cyl_Up == 1) || Insp1_Cyl_Up;
            Insp1_Cyl_Dn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y031_1_Insp_Cyl_Dn == 1) || Insp1_Cyl_Dn;

            Kernel.Exc.DO.Y032_1_Insp_Vacuum = (byte)(((ManualMode && Insp1_ToVacOnn) || Insp1_ToVacOnn_A) || (Kernel.Exc.DO.Y032_1_Insp_Vacuum == 1 && !Insp1_ToVacOff && !Insp1_ToVacOff_A) ? 1 : 0);
            Kernel.Exc.DO.Y033_1_Insp_VacBrk = (byte)(((ManualMode && Insp1_ToVacOff) || Insp1_ToVacOff_A) ? 1 : 0);
            Insp1_ToVacOnn  = false;
            Insp1_ToVacOff = false;
            Insp1_VacOnn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y032_1_Insp_Vacuum == 1) || Insp1_VacOnn;
            Insp1_VacOff_BL = ( Kernel.Exc.DO.Y033_1_Insp_VacBrk == 1);


            Kernel.Exc.DO.Y038_2_Insp_Cyl_Up = (byte)(((ManualMode && Insp2_Cyl_ToUp) || Insp2_Cyl_ToUp_A) || (Kernel.Exc.DO.Y038_2_Insp_Cyl_Up == 1 && !Insp2_Cyl_ToDn && !Insp2_Cyl_ToDn_A) ? 1 : 0);
            Kernel.Exc.DO.Y039_2_Insp_Cyl_Dn = (byte)(((ManualMode && Insp2_Cyl_ToDn) || Insp2_Cyl_ToDn_A) || (Kernel.Exc.DO.Y039_2_Insp_Cyl_Dn == 1 && !Insp2_Cyl_ToUp && !Insp2_Cyl_ToUp_A) ? 1 : 0);
            Insp2_Cyl_ToUp = false;
            Insp2_Cyl_ToDn = false;
            Insp2_Cyl_Up_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y038_2_Insp_Cyl_Up == 1) || Insp2_Cyl_Up;
            Insp2_Cyl_Dn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y039_2_Insp_Cyl_Dn == 1) || Insp2_Cyl_Dn;

            Kernel.Exc.DO.Y03A_2_Insp_Vacuum = (byte)(((ManualMode && Insp2_ToVacOnn) || Insp2_ToVacOnn_A) || (Kernel.Exc.DO.Y03A_2_Insp_Vacuum == 1 && !Insp2_ToVacOff && !Insp2_ToVacOff_A) ? 1 : 0);
            Kernel.Exc.DO.Y03B_2_Insp_VacBrk = (byte)(((ManualMode && Insp2_ToVacOff) || Insp2_ToVacOff_A)  ? 1 : 0);
            Insp2_ToVacOnn = false;
            Insp2_ToVacOff = false;
            Insp2_VacOnn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y03A_2_Insp_Vacuum == 1) || Insp2_VacOnn;
            Insp2_VacOff_BL = (Kernel.Exc.DO.Y03B_2_Insp_VacBrk == 1) ;

            Kernel.Exc.DO.Y040_3_Insp_Cyl_Up = (byte)(((ManualMode && Insp3_Cyl_ToUp) || Insp3_Cyl_ToUp_A) || (Kernel.Exc.DO.Y040_3_Insp_Cyl_Up == 1 && !Insp3_Cyl_ToDn && !Insp3_Cyl_ToDn_A) ? 1 : 0);
            Kernel.Exc.DO.Y041_3_Insp_Cyl_Dn = (byte)(((ManualMode && Insp3_Cyl_ToDn) || Insp3_Cyl_ToDn_A) || (Kernel.Exc.DO.Y041_3_Insp_Cyl_Dn == 1 && !Insp3_Cyl_ToUp && !Insp3_Cyl_ToUp_A) ? 1 : 0);
            Insp3_Cyl_ToUp = false;
            Insp3_Cyl_ToDn = false;
            Insp3_Cyl_Up_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y040_3_Insp_Cyl_Up == 1) || Insp3_Cyl_Up;
            Insp3_Cyl_Dn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y041_3_Insp_Cyl_Dn == 1) || Insp3_Cyl_Dn;

            Kernel.Exc.DO.Y042_3_Insp_Vacuum = (byte)(((ManualMode && Insp3_ToVacOnn) || Insp3_ToVacOnn_A) || (Kernel.Exc.DO.Y042_3_Insp_Vacuum == 1 && !Insp3_ToVacOff && !Insp3_ToVacOff_A) ? 1 : 0);
            Kernel.Exc.DO.Y043_3_Insp_VacBrk = (byte)(((ManualMode && Insp3_ToVacOff) || Insp3_ToVacOff_A)  ? 1 : 0);
            Insp3_ToVacOnn = false;
            Insp3_ToVacOff = false;
            Insp3_VacOnn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y042_3_Insp_Vacuum == 1) || Insp3_VacOnn;
            Insp3_VacOff_BL = (Kernel.Exc.DO.Y043_3_Insp_VacBrk == 1);

            Kernel.Exc.DO.Y048_4_Insp_Cyl_Up = (byte)(((ManualMode && Insp4_Cyl_ToUp) || Insp4_Cyl_ToUp_A) || (Kernel.Exc.DO.Y048_4_Insp_Cyl_Up == 1 && !Insp4_Cyl_ToDn && !Insp4_Cyl_ToDn_A) ? 1 : 0);
            Kernel.Exc.DO.Y049_4_Insp_Cyl_Dn = (byte)(((ManualMode && Insp4_Cyl_ToDn) || Insp4_Cyl_ToDn_A) || (Kernel.Exc.DO.Y049_4_Insp_Cyl_Dn == 1 && !Insp4_Cyl_ToUp && !Insp4_Cyl_ToUp_A) ? 1 : 0);
            Insp4_Cyl_ToUp = false;
            Insp4_Cyl_ToDn = false;
            Insp4_Cyl_Up_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y048_4_Insp_Cyl_Up == 1) || Insp4_Cyl_Up;
            Insp4_Cyl_Dn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y049_4_Insp_Cyl_Dn == 1) || Insp4_Cyl_Dn;

            Kernel.Exc.DO.Y04A_4_Insp_Vacuum = (byte)(((ManualMode && Insp4_ToVacOnn) || Insp4_ToVacOnn_A) || (Kernel.Exc.DO.Y04A_4_Insp_Vacuum == 1 && !Insp4_ToVacOff && !Insp4_ToVacOff_A) ? 1 : 0);
            Kernel.Exc.DO.Y04B_4_Insp_VacBrk = (byte)(((ManualMode && Insp4_ToVacOff) || Insp4_ToVacOff_A) ? 1 : 0);
            Insp4_ToVacOnn = false;
            Insp4_ToVacOff = false;
            Insp4_VacOnn_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y04A_4_Insp_Vacuum == 1) || Insp4_VacOnn;
            Insp4_VacOff_BL = Kernel.Exc.DO.Y04B_4_Insp_VacBrk == 1;

            Kernel.Exc.DO.Y058_SafeDoor1_Lock = (byte)(((ManualMode && SafeDoor1_ToLockk) || SafeDoor1_ToLockk_A) || (Kernel.Exc.DO.Y058_SafeDoor1_Lock == 1 && !SafeDoor1_ToULock) ? 1 : 0);
            Kernel.Exc.DO.Y059_SafeDoor2_Lock = (byte)(((ManualMode && SafeDoor2_ToLockk) || SafeDoor2_ToLockk_A) || (Kernel.Exc.DO.Y059_SafeDoor2_Lock == 1 && !SafeDoor2_ToULock) ? 1 : 0);
            SafeDoor1_ToLockk = false;
            SafeDoor2_ToLockk = false;
            SafeDoor1_ToLockk_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y058_SafeDoor1_Lock == 1) || SafeDoor1_Lockk;
            SafeDoor2_ToLockk_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y059_SafeDoor2_Lock == 1) || SafeDoor2_Lockk;
            #endregion

            Kernel.Exc.DO.Y060_UpStr_CH1_Rev_Ready = (byte)(((ManualMode && ToUp_CH1_Ready_M) || ToUp_CH1_Ready_A) || (Kernel.Exc.DO.Y060_UpStr_CH1_Rev_Ready == 1 && !ToUp_CH1_Ready_Cancel_M && !ToUp_CH1_Ready_Cancel_A) ? 1 : 0);
            Kernel.Exc.DO.Y061_UpStr_CH1_receiving = (byte)(((ManualMode && ToUp_CH1_Receiving_M) || ToUp_CH1_Receiving_A) || (Kernel.Exc.DO.Y061_UpStr_CH1_receiving == 1 && !ToUp_CH1_Receiving_Cancel_M && !ToUp_CH1_Receiving_Cancel_A) ? 1 : 0);
            ToUp_CH1_Ready_M = false;
            ToUp_CH1_Ready_Cancel_M = false;
            ToUp_CH1_Receiving_M = false;
            ToUp_CH1_Receiving_Cancel_M = false;
            ToUp_CH1_Ready = Kernel.Exc.DO.Y060_UpStr_CH1_Rev_Ready == 1; 
            ToUp_CH1_Receiving = Kernel.Exc.DO.Y061_UpStr_CH1_receiving == 1;

            Kernel.Exc.DO.Y062_UpStr_CH2_Rev_Ready = (byte)(((ManualMode && ToUp_CH2_Ready_M) || ToUp_CH2_Ready_A) || (Kernel.Exc.DO.Y062_UpStr_CH2_Rev_Ready == 1 && !ToUp_CH2_Ready_Cancel_M && !ToUp_CH2_Ready_Cancel_A) ? 1 : 0);
            Kernel.Exc.DO.Y063_UpStr_CH2_receiving = (byte)(((ManualMode && ToUp_CH2_Receiving_M) || ToUp_CH2_Receiving_A) || (Kernel.Exc.DO.Y063_UpStr_CH2_receiving == 1 && !ToUp_CH2_Receiving_Cancel_M && !ToUp_CH2_Receiving_Cancel_A) ? 1 : 0);
            ToUp_CH2_Ready_M = false;
            ToUp_CH2_Ready_Cancel_M = false;
            ToUp_CH2_Receiving_M = false;
            ToUp_CH2_Receiving_Cancel_M = false;
            ToUp_CH2_Ready = Kernel.Exc.DO.Y062_UpStr_CH2_Rev_Ready == 1;
            ToUp_CH2_Receiving = Kernel.Exc.DO.Y063_UpStr_CH2_receiving == 1;

            Kernel.Exc.DO.Y064_UpStr_CH3_Rev_Ready = (byte)(((ManualMode && ToUp_CH3_Ready_M) || ToUp_CH3_Ready_A) || (Kernel.Exc.DO.Y064_UpStr_CH3_Rev_Ready == 1 && !ToUp_CH3_Ready_Cancel_M && !ToUp_CH3_Ready_Cancel_A) ? 1 : 0);
            Kernel.Exc.DO.Y065_UpStr_CH3_receiving = (byte)(((ManualMode && ToUp_CH3_Receiving_M) || ToUp_CH3_Receiving_A) || (Kernel.Exc.DO.Y065_UpStr_CH3_receiving == 1 && !ToUp_CH3_Receiving_Cancel_M && !ToUp_CH3_Receiving_Cancel_A) ? 1 : 0);
            ToUp_CH3_Ready_M = false;
            ToUp_CH3_Ready_Cancel_M = false;
            ToUp_CH3_Receiving_M = false;
            ToUp_CH3_Receiving_Cancel_M = false;
            ToUp_CH3_Ready = Kernel.Exc.DO.Y064_UpStr_CH3_Rev_Ready == 1;
            ToUp_CH3_Receiving = Kernel.Exc.DO.Y065_UpStr_CH3_receiving == 1;

            Kernel.Exc.DO.Y066_UpStr_CH4_Rev_Ready = (byte)(((ManualMode && ToUp_CH4_Ready_M) || ToUp_CH4_Ready_A) || (Kernel.Exc.DO.Y066_UpStr_CH4_Rev_Ready == 1 && !ToUp_CH4_Ready_Cancel_M && !ToUp_CH4_Ready_Cancel_A) ? 1 : 0);
            Kernel.Exc.DO.Y067_UpStr_CH4_receiving = (byte)(((ManualMode && ToUp_CH4_Receiving_M) || ToUp_CH4_Receiving_A) || (Kernel.Exc.DO.Y067_UpStr_CH4_receiving == 1 && !ToUp_CH4_Receiving_Cancel_M && !ToUp_CH4_Receiving_Cancel_A) ? 1 : 0);
            ToUp_CH4_Ready_M = false;
            ToUp_CH4_Ready_Cancel_M = false;
            ToUp_CH4_Receiving_M = false;
            ToUp_CH4_Receiving_Cancel_M = false;
            ToUp_CH4_Ready = Kernel.Exc.DO.Y066_UpStr_CH4_Rev_Ready == 1;
            ToUp_CH4_Receiving = Kernel.Exc.DO.Y067_UpStr_CH4_receiving == 1;

            Kernel.Exc.DO.Y068_DnStr_CH1_SendReady = (byte)(((ManualMode && ToDn_CH1_Ready_M) || ToDn_CH1_Ready_A) || (Kernel.Exc.DO.Y068_DnStr_CH1_SendReady == 1 && !ToDn_CH1_Ready_Cancel_M && !ToDn_CH1_Ready_Cancel_A) ? 1 : 0);
            Kernel.Exc.DO.Y069_DnStr_CH1_Sending = (byte)(((ManualMode && ToDn_CH1_Sending_M) || ToDn_CH1_Sending_A) || (Kernel.Exc.DO.Y069_DnStr_CH1_Sending == 1 && !ToDn_CH1_Sending_Cancel_M && !ToDn_CH1_Sending_Cancel_A) ? 1 : 0);
            ToDn_CH1_Ready_M = false;
            ToDn_CH1_Ready_Cancel_M = false;
            ToDn_CH1_Sending_M = false;
            ToDn_CH1_Sending_Cancel_M = false;
            ToDn_CH1_Ready = Kernel.Exc.DO.Y068_DnStr_CH1_SendReady == 1;
            ToDn_CH1_Sending = Kernel.Exc.DO.Y069_DnStr_CH1_Sending == 1;

            Kernel.Exc.DO.Y06A_DnStr_CH2_SendReady = (byte)(((ManualMode && ToDn_CH2_Ready_M) || ToDn_CH2_Ready_A) || (Kernel.Exc.DO.Y06A_DnStr_CH2_SendReady == 1 && !ToDn_CH2_Ready_Cancel_M && !ToDn_CH2_Ready_Cancel_A) ? 1 : 0);
            Kernel.Exc.DO.Y06B_DnStr_CH2_Sending = (byte)(((ManualMode && ToDn_CH2_Sending_M) || ToDn_CH2_Sending_A) || (Kernel.Exc.DO.Y06B_DnStr_CH2_Sending == 1 && !ToDn_CH2_Sending_Cancel_M && !ToDn_CH2_Sending_Cancel_A) ? 1 : 0);
            ToDn_CH2_Ready_M = false;
            ToDn_CH2_Ready_Cancel_M = false;
            ToDn_CH2_Sending_M = false;
            ToDn_CH2_Sending_Cancel_M = false;
            ToDn_CH2_Ready = Kernel.Exc.DO.Y06A_DnStr_CH2_SendReady == 1;
            ToDn_CH2_Sending = Kernel.Exc.DO.Y06B_DnStr_CH2_Sending == 1;

            Kernel.Exc.DO.Y06C_DnStr_CH3_SendReady = (byte)(((ManualMode && ToDn_CH3_Ready_M) || ToDn_CH3_Ready_A) || (Kernel.Exc.DO.Y06C_DnStr_CH3_SendReady == 1 && !ToDn_CH3_Ready_Cancel_M && !ToDn_CH3_Ready_Cancel_A) ? 1 : 0);
            Kernel.Exc.DO.Y06D_DnStr_CH3_Sending = (byte)(((ManualMode && ToDn_CH3_Sending_M) || ToDn_CH3_Sending_A) || (Kernel.Exc.DO.Y06D_DnStr_CH3_Sending == 1 && !ToDn_CH3_Sending_Cancel_M && !ToDn_CH3_Sending_Cancel_A) ? 1 : 0);
            ToDn_CH3_Ready_M = false;
            ToDn_CH3_Ready_Cancel_M = false;
            ToDn_CH3_Sending_M = false;
            ToDn_CH3_Sending_Cancel_M = false;
            ToDn_CH3_Ready = Kernel.Exc.DO.Y06C_DnStr_CH3_SendReady == 1;
            ToDn_CH3_Sending = Kernel.Exc.DO.Y06D_DnStr_CH3_Sending == 1;

            Kernel.Exc.DO.Y06E_DnStr_CH4_SendReady = (byte)(((ManualMode && ToDn_CH4_Ready_M) || ToDn_CH4_Ready_A) || (Kernel.Exc.DO.Y06E_DnStr_CH4_SendReady == 1 && !ToDn_CH4_Ready_Cancel_M && !ToDn_CH4_Ready_Cancel_A) ? 1 : 0);
            Kernel.Exc.DO.Y06F_DnStr_CH4_Sending = (byte)(((ManualMode && ToDn_CH4_Sending_M) || ToDn_CH4_Sending_A) || (Kernel.Exc.DO.Y06F_DnStr_CH4_Sending == 1 && !ToDn_CH4_Sending_Cancel_M && !ToDn_CH4_Sending_Cancel_A) ? 1 : 0);
            ToDn_CH4_Ready_M = false;
            ToDn_CH4_Ready_Cancel_M = false;
            ToDn_CH4_Sending_M = false;
            ToDn_CH4_Sending_Cancel_M = false;
            ToDn_CH4_Ready = Kernel.Exc.DO.Y06A_DnStr_CH2_SendReady == 1;
            ToDn_CH4_Sending = Kernel.Exc.DO.Y06B_DnStr_CH2_Sending == 1;

            CodeRead1_Completed = Kernel.codeRead1.IsReadOK && Kernel.Exc.DI.X021_CV1_Stop==1;
            CodeRead2_Completed = Kernel.codeRead2.IsReadOK && Kernel.Exc.DI.X027_CV2_Stop == 1;

            CodeRead1 = CodeRead1_M || CodeRead1_A;
            CodeRead2 = CodeRead2_M || CodeRead2_A;
            CodeRead1_M = false;
            CodeRead2_M = false;

            Kernel.codeRead1.Sending = CodeRead1;
            Kernel.codeRead2.Sending = CodeRead2;


#if false

            LaserST7_Vac_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y1D7_Laser_Vac7 == 1) || LaserST7_Vac;

            Kernel.Exc.DO.Y1D8_Laser_Vac8 =
              (byte)(((ManualMode && LaserST8_ToVacOn) || LaserST8_ToVacOn_A) || (Kernel.Exc.DO.Y1D8_Laser_Vac8 == 1 && !LaserST8_ToVacOff && !LaserST8_ToVacOff_A) ? 1 : 0);
            LaserST8_ToVacOn = false;
            LaserST8_ToVacOff = false;

            LaserST8_Vac_BL = (PulseOn.Pulse_1s && Kernel.Exc.DO.Y1D8_Laser_Vac8 == 1) || LaserST8_Vac;

            Kernel.Exc.DO.Y1D9_ULDST_Vac =
             (byte)(((ManualMode && ULDST_ToVacOn) || ULDST_ToVacOn_A) || (Kernel.Exc.DO.Y1D9_ULDST_Vac == 1 && !ULDST_ToVacOff && !ULDST_ToVacOff_A) ? 1 : 0);
            ULDST_ToVacOn = false;
            ULDST_ToVacOff = false;

            Kernel.Exc.DO.Y207_ExcIon_Open = (byte)((AutoMode) ? 1 : 0);

            Kernel.Exc.DO.Y1EE_ExcST_CodeReadLight = (byte)((((ManualMode && ExcST_CodeReadLightOn) || ExcST_CodeReadLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F0_BallLight_Exc = (byte)((((ManualMode && ExcST_BallLightOn) || ExcST_BallLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F1_CoaxialLight_Exc = (byte)((((ManualMode && ExcST_CoaxialLightOn) || ExcST_CoaxialLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F2_PreAlignLight_SortST = (byte)((((ManualMode && SortST_PreAlignLightOn) || SortST_PreAlignLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F3_FinalAlignLight_SortST = (byte)((((ManualMode && SortST_FinalAlignLightOn) || SortST_FinalAlignLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F4_UpperCoaxialLight_Laser = (byte)((((ManualMode && LaserST_UpperCoaxialLightOn) || LaserST_UpperCoaxialLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F5_SideCoaxialLight_Laser = (byte)((((ManualMode && LaserST_SideCoaxialLightOn) || LaserST_SideCoaxialLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F6_InspCoaxialLight_Laser = (byte)((((ManualMode && LaserST_InspCoaxialLightOn) || LaserST_InspCoaxialLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F7_AlignLight_ULDTR1 = (byte)((((ManualMode && ULDTR1_AlignLightOn) || ULDTR1_AlignLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F8_AlignLight_ULDTR2 = (byte)((((ManualMode && ULDTR2_AlignLightOn) || ULDTR2_AlignLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1F9_PreAlignLight_ULDST = (byte)((((ManualMode && ULDST_PreAlignLightOn) || ULDST_PreAlignLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1FA_FinalAlignLight_ULDST = (byte)((((ManualMode && ULDST_FinalAlignLightOn) || ULDST_FinalAlignLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1FB_RingLight_Efem = (byte)((((ManualMode && Efem_RingLightOn) || Efem_RingLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1FC_CoaxialLight_Efem = (byte)((((ManualMode && Efem_CoaxialLightOn) || Efem_CoaxialLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1FD_UpperBallLight_Laser = (byte)((((ManualMode && LaserST_UpperBallLightOn) || LaserST_UpperBallLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1FE_SideBackLight_Laser = (byte)((((ManualMode && LaserST_SideBackLightOn) || LaserST_SideBackLightOn_A)) ? 1 : 0);
            Kernel.Exc.DO.Y1FF_InspBallLight_Laser = (byte)((((ManualMode && LaserST_InspBallLightOn) || LaserST_InspBallLightOn_A)) ? 1 : 0);

            timecot1++;

#endif
        }

        private void LogMsg(string msg)
        {
            LogHelper.Write(LogHelper.Module.Motion, msg);
        }

        int timecot = 0;
        bool blnT = false;
        bool blnT1 = false;
        SystemTimeCounter time = new SystemTimeCounter();
        SystemTimeCounter time_1S = new SystemTimeCounter();
        bool musicRet = false;
        object lockObj = new object();
        private bool Music(int interval = 2)
        {
            lock (lockObj)
            {
                if (timecot < 3)
                {
                    if (time.Duration >= 400)
                    {
                        musicRet = !musicRet;
                        time.Start();
                    }
                }
                else
                {
                    musicRet = false;
                    time.Start();
                }

                if (time_1S.Duration > 1000)
                {
                    timecot++;
                    time_1S.Start();
                }

                if (timecot >= interval)
                {
                    timecot = 0;
                    //musicRet = false;
                }
            }

            return musicRet;
        }


        static double[] Pos_CV1_TrackSW_Y = new double[20];
        static double[] Pos_CV2_TrackSW_Y = new double[20];
        static double[] Pos_CV1_Y = new double[20];
        static double[] Pos_CV2_Y = new double[20];

        static double[] Pos_CCD1_X = new double[20];
        static double[] Pos_CCD1_Y = new double[20];
        static double[] Pos_CCD1_Z = new double[20];
        static double[] Pos_CCD2_X = new double[20];
        static double[] Pos_CCD2_Y = new double[20];
        static double[] Pos_CCD2_Z = new double[20];
        static double[] Pos_Insp1_Y = new double[20];
        static double[] Pos_Insp2_Y = new double[20];
        static double[] Pos_Insp3_Y = new double[20];
        static double[] Pos_Insp4_Y = new double[20];
        static double[] Pos_Insp1_RM_Z = new double[20];
        static double[] Pos_Insp2_RM_Z = new double[20];
        static double[] Pos_Insp3_RM_Z = new double[20];
        static double[] Pos_Insp4_RM_Z = new double[20];

        static bool CV1_TrackSW_Y_Stop = false;
        static bool CV1_TrackSW_Y_HomeCondition = false;
        static bool CV1_TrackSW_Y_MoveCondition = false;
        static bool CV1_TrackSW_Y_Homing = false;
        static bool CV1_TrackSW_Y_Runing = false;
        /// <summary>
        /// 1-接料 2-检测1 3-检测2
        /// </summary>
        static int CV1_TrackSW_Y_RunCode = 0;

        static bool CV2_TrackSW_Y_Stop = false;
        static bool CV2_TrackSW_Y_HomeCondition = false;
        static bool CV2_TrackSW_Y_MoveCondition = false;
        static bool CV2_TrackSW_Y_Homing = false;
        static bool CV2_TrackSW_Y_Runing = false;
        /// <summary>
        /// 1-接料 2-检测1 3-检测2
        /// </summary>
        static int  CV2_TrackSW_Y_RunCode = 0;

        static bool CCD1_X_Stop = false;
        static bool CCD1_X_HomeCondition = false;
        static bool CCD1_X_MoveCondition = false;
        static bool CCD1_X_Homing = false;
        static bool CCD1_X_Runing = false;
        /// <summary>
        /// 1-CH1_Mark 2-CH1_Work 3-CH2_Mark 4-CH2_Work 5-Wait
        /// </summary>
        static int  CCD1_X_RunCode = 0;

        static bool CCD1_Y_Stop = false;
        static bool CCD1_Y_HomeCondition = false;
        static bool CCD1_Y_MoveCondition = false;
        static bool CCD1_Y_Homing = false;
        static bool CCD1_Y_Runing = false;
        /// <summary>
        /// 1-CH1_Mark 2-CH1_Work 3-CH2_Mark 4-CH2_Work 5-Wait
        /// </summary>
        static int  CCD1_Y_RunCode = 0;

        static bool CCD1_Z_Stop = false;
        static bool CCD1_Z_HomeCondition = false;
        static bool CCD1_Z_MoveCondition = false;
        static bool CCD1_Z_Homing = false;
        static bool CCD1_Z_Runing = false;
        /// <summary>
        /// 1-CH1_Mark 2-CH1_Work 3-CH2_Mark 4-CH2_Work 5-Wait
        /// </summary>
        static int  CCD1_Z_RunCode = 0;

        static bool CCD2_X_Stop = false;
        static bool CCD2_X_HomeCondition = false;
        static bool CCD2_X_MoveCondition = false;
        static bool CCD2_X_Homing = false;
        static bool CCD2_X_Runing = false;
        /// <summary>
        /// 1-CH1_Mark 2-CH1_Work 3-CH2_Mark 4-CH2_Work 5-Wait
        /// </summary>
        static int  CCD2_X_RunCode = 0;

        static bool CCD2_Y_Stop = false;
        static bool CCD2_Y_HomeCondition = false;
        static bool CCD2_Y_MoveCondition = false;
        static bool CCD2_Y_Homing = false;
        static bool CCD2_Y_Runing = false;
        /// <summary>
        /// 1-CH1_Mark 2-CH1_Work 3-CH2_Mark 4-CH2_Work 5-Wait
        /// </summary>
        static int  CCD2_Y_RunCode = 0;

        static bool CCD2_Z_Stop = false;
        static bool CCD2_Z_HomeCondition = false;
        static bool CCD2_Z_MoveCondition = false;
        static bool CCD2_Z_Homing = false;
        static bool CCD2_Z_Runing = false;
        /// <summary>
        /// 1-CH1_Mark 2-CH1_Work 3-CH2_Mark 4-CH2_Work 5-Wait
        /// </summary>
        static int  CCD2_Z_RunCode = 0;

        static bool CV1_Y_Stop = false;
        static bool CV1_Y_HomeCondition = false;
        static bool CV1_Y_MoveCondition = false;
        static bool CV1_Y_Homing = false;
        static bool CV1_Y_Runing = false;
        static int CV1_Y_RunCode = 0;

        static bool CV2_Y_Stop = false;
        static bool CV2_Y_HomeCondition = false;
        static bool CV2_Y_MoveCondition = false;
        static bool CV2_Y_Homing = false;
        static bool CV2_Y_Runing = false;
        static int  CV2_Y_RunCode = 0;

        static bool Insp1_Y_Stop = false;
        static bool Insp1_Y_HomeCondition = false;
        static bool Insp1_Y_MoveCondition = false;
        static bool Insp1_Y_Homing = false;
        static bool Insp1_Y_Runing = false;
        static int Insp1_Y_RunCode = 0;

        static bool Insp2_Y_Stop = false;
        static bool Insp2_Y_HomeCondition = false;
        static bool Insp2_Y_MoveCondition = false;
        static bool Insp2_Y_Homing = false;
        static bool Insp2_Y_Runing = false;
        static int  Insp2_Y_RunCode = 0;

        static bool Insp3_Y_Stop = false;
        static bool Insp3_Y_HomeCondition = false;
        static bool Insp3_Y_MoveCondition = false;
        static bool Insp3_Y_Homing = false;
        static bool Insp3_Y_Runing = false;
        static int  Insp3_Y_RunCode = 0;

        static bool Insp4_Y_Stop = false;
        static bool Insp4_Y_HomeCondition = false;
        static bool Insp4_Y_MoveCondition = false;
        static bool Insp4_Y_Homing = false;
        static bool Insp4_Y_Runing = false;
        static int  Insp4_Y_RunCode = 0;

        static bool Insp1_RM_Z_Stop = false;
        static bool Insp1_RM_Z_HomeCondition = false;
        static bool Insp1_RM_Z_MoveCondition = false;
        static bool Insp1_RM_Z_Homing = false;
        static bool Insp1_RM_Z_Runing = false;
        static int  Insp1_RM_Z_RunCode = 0;

        static bool Insp2_RM_Z_Stop = false;
        static bool Insp2_RM_Z_HomeCondition = false;
        static bool Insp2_RM_Z_MoveCondition = false;
        static bool Insp2_RM_Z_Homing = false;
        static bool Insp2_RM_Z_Runing = false;
        static int  Insp2_RM_Z_RunCode = 0;

        static bool Insp3_RM_Z_Stop = false;
        static bool Insp3_RM_Z_HomeCondition = false;
        static bool Insp3_RM_Z_MoveCondition = false;
        static bool Insp3_RM_Z_Homing = false;
        static bool Insp3_RM_Z_Runing = false;
        static int  Insp3_RM_Z_RunCode = 0;

        static bool Insp4_RM_Z_Stop = false;
        static bool Insp4_RM_Z_HomeCondition = false;
        static bool Insp4_RM_Z_MoveCondition = false;
        static bool Insp4_RM_Z_Homing = false;
        static bool Insp4_RM_Z_Runing = false;
        static int  Insp4_RM_Z_RunCode = 0;


        #region  OLD

        static bool ExcST_Stop = false;
        static bool ExcST_Y_Stop = false;
        static bool ExcST_R_Stop = false;

        static bool ExcST_HomeCondition = false;
        static bool ExcST_Y_HomeCondition = false;
        static bool ExcST_R_HomeCondition = false;

        static bool ExcST_MoveCondition = false;
        static bool ExcST_Y_MoveCondition = false;
        static bool ExcST_R_MoveCondition = false;

        static bool ExcST_Y_Homing = false;
        static bool ExcST_R_Homing = false;

        static bool ExcST_Y_Runing = false;
        static bool ExcST_R_Runing = false;

        static int ExcST_Y_RunCode = 0;
        static int ExcST_R_RunCode = 0;

        static bool ExcCCD_Stop = false;
        static bool ExcCCD_HomeCondition = false;
        static bool ExcCCD_MoveCondition = false;
        static bool ExcCCD_Homing = false;
        static bool ExcCCD_Runing = false;
        static int ExcCCD_RunCode = 0;

        static bool ExcTR_X_Stop = false;
        static bool ExcTR_X_HomeCondition = false;
        static bool ExcTR_X_MoveCondition = false;
        static bool ExcTR_X_Homing = false;
        static bool ExcTR_X_Runing = false;
        static int ExcTR_X_RunCode = 0;

        static bool ExcTR_Z_Stop = false;
        static bool ExcTR_Z_HomeCondition = false;
        static bool ExcTR_Z_MoveCondition = false;
        static bool ExcTR_Z_Homing = false;
        static bool ExcTR_Z_Runing = false;
        static int ExcTR_Z_RunCode = 0;

        static bool ExcTR_R_Stop = false;
        static bool ExcTR_R_HomeCondition = false;
        static bool ExcTR_R_MoveCondition = false;
        static bool ExcTR_R_Homing = false;
        static bool ExcTR_R_Runing = false;
        static int ExcTR_R_RunCode = 0;

        static bool SortST_X_Stop = false;
        static bool SortST_X_HomeCondition = false;
        static bool SortST_X_MoveCondition = false;
        static bool SortST_X_Homing = false;
        static bool SortST_X_Runing = false;
        static int SortST_X_RunCode = 0;

        static bool SortST_Y_Stop = false;
        static bool SortST_Y_HomeCondition = false;
        static bool SortST_Y_MoveCondition = false;
        static bool SortST_Y_Homing = false;
        static bool SortST_Y_Runing = false;
        static int SortST_Y_RunCode = 0;

        static bool SortST_R_Stop = false;
        static bool SortST_R_HomeCondition = false;
        static bool SortST_R_MoveCondition = false;
        static bool SortST_R_Homing = false;
        static bool SortST_R_Runing = false;
        static int SortST_R_RunCode = 0;

        static bool LDTR_R_Stop = false;
        static bool LDTR_R_HomeCondition = false;
        static bool LDTR_R_MoveCondition = false;
        static bool LDTR_R_Homing = false;
        static bool LDTR_R_Runing = false;
        static int LDTR_R_RunCode = 0;

        static bool LDTR_CCD_Stop = false;
        static bool LDTR_CCD_HomeCondition = false;
        static bool LDTR_CCD_MoveCondition = false;
        static bool LDTR_CCD_Homing = false;
        static bool LDTR_CCD_Runing = false;
        static int LDTR_CCD_RunCode = 0;

        static bool LDTR_1_Z_Stop = false;
        static bool LDTR_1_Z_HomeCondition = false;
        static bool LDTR_1_Z_MoveCondition = false;
        static bool LDTR_1_Z_Homing = false;
        static bool LDTR_1_Z_Runing = false;
        static int LDTR_1_Z_RunCode = 0;

        static bool LDTR_1_R_Stop = false;
        static bool LDTR_1_R_HomeCondition = false;
        static bool LDTR_1_R_MoveCondition = false;
        static bool LDTR_1_R_Homing = false;
        static bool LDTR_1_R_Runing = false;
        static int LDTR_1_R_RunCode = 0;

        static bool LDTR_2_Z_Stop = false;
        static bool LDTR_2_Z_HomeCondition = false;
        static bool LDTR_2_Z_MoveCondition = false;
        static bool LDTR_2_Z_Homing = false;
        static bool LDTR_2_Z_Runing = false;
        static int LDTR_2_Z_RunCode = 0;

        static bool LDTR_2_R_Stop = false;
        static bool LDTR_2_R_HomeCondition = false;
        static bool LDTR_2_R_MoveCondition = false;
        static bool LDTR_2_R_Homing = false;
        static bool LDTR_2_R_Runing = false;
        static int LDTR_2_R_RunCode = 0;

        static bool ULDTR_R_Stop = false;
        static bool ULDTR_R_HomeCondition = false;
        static bool ULDTR_R_MoveCondition = false;
        static bool ULDTR_R_Homing = false;
        static bool ULDTR_R_Runing = false;
        static int ULDTR_R_RunCode = 0;

        static bool ULDTR_CCD_Stop = false;
        static bool ULDTR_CCD_HomeCondition = false;
        static bool ULDTR_CCD_MoveCondition = false;
        static bool ULDTR_CCD_Homing = false;
        static bool ULDTR_CCD_Runing = false;
        static int ULDTR_CCD_RunCode = 0;

        static bool ULDTR_1_Z_Stop = false;
        static bool ULDTR_1_Z_HomeCondition = false;
        static bool ULDTR_1_Z_MoveCondition = false;
        static bool ULDTR_1_Z_Homing = false;
        static bool ULDTR_1_Z_Runing = false;
        static int ULDTR_1_Z_RunCode = 0;

        static bool ULDTR_1_R_Stop = false;
        static bool ULDTR_1_R_HomeCondition = false;
        static bool ULDTR_1_R_MoveCondition = false;
        static bool ULDTR_1_R_Homing = false;
        static bool ULDTR_1_R_Runing = false;
        static int ULDTR_1_R_RunCode = 0;

        static bool ULDTR_2_Z_Stop = false;
        static bool ULDTR_2_Z_HomeCondition = false;
        static bool ULDTR_2_Z_MoveCondition = false;
        static bool ULDTR_2_Z_Homing = false;
        static bool ULDTR_2_Z_Runing = false;
        static int ULDTR_2_Z_RunCode = 0;

        static bool ULDTR_2_R_Stop = false;
        static bool ULDTR_2_R_HomeCondition = false;
        static bool ULDTR_2_R_MoveCondition = false;
        static bool ULDTR_2_R_Homing = false;
        static bool ULDTR_2_R_Runing = false;
        static int ULDTR_2_R_RunCode = 0;

        static bool LaserST_R_Stop = false;
        static bool LaserST_R_HomeCondition = false;
        static bool LaserST_R_MoveCondition = false;
        static bool LaserST_R_Homing = false;
        static bool LaserST_R_Runing = false;
        static int LaserST_R_RunCode = 0;

        static bool LaserST_CCD1_Stop = false;
        static bool LaserST_CCD1_HomeCondition = false;
        static bool LaserST_CCD1_MoveCondition = false;
        static bool LaserST_CCD1_Homing = false;
        static bool LaserST_CCD1_Runing = false;
        static int LaserST_CCD1_RunCode = 0;

        static bool LaserST_CCD2_Stop = false;
        static bool LaserST_CCD2_HomeCondition = false;
        static bool LaserST_CCD2_MoveCondition = false;
        static bool LaserST_CCD2_Homing = false;
        static bool LaserST_CCD2_Runing = false;
        static int LaserST_CCD2_RunCode = 0;

        static bool LaserST_CCD3_Stop = false;
        static bool LaserST_CCD3_HomeCondition = false;
        static bool LaserST_CCD3_MoveCondition = false;
        static bool LaserST_CCD3_Homing = false;
        static bool LaserST_CCD3_Runing = false;
        static int LaserST_CCD3_RunCode = 0;

        static bool ULDST_CCD_Stop = false;
        static bool ULDST_CCD_HomeCondition = false;
        static bool ULDST_CCD_MoveCondition = false;
        static bool ULDST_CCD_Homing = false;
        static bool ULDST_CCD_Runing = false;
        static int ULDST_CCD_RunCode = 0;

        static bool ULDST_Ext_Stop = false;
        static bool ULDST_Ext_HomeCondition = false;
        static bool ULDST_Ext_MoveCondition = false;
        static bool ULDST_Ext_Homing = false;
        static bool ULDST_Ext_Runing = false;
        static int ULDST_Ext_RunCode = 0;

        static bool ULDST_Stop = false;
        static bool ULDST_Y_Stop = false;
        static bool ULDST_X_Stop = false;

        static bool ULDST_HomeCondition = false;
        static bool ULDST_Y_HomeCondition = false;
        static bool ULDST_X_HomeCondition = false;

        static bool ULDST_MoveCondition = false;
        static bool ULDST_Y_MoveCondition = false;
        static bool ULDST_X_MoveCondition = false;

        static bool ULDST_Y_Homing = false;
        static bool ULDST_X_Homing = false;

        static bool ULDST_Y_Runing = false;
        static bool ULDST_X_Runing = false;

        static int ULDST_Y_RunCode = 0;
        static int ULDST_X_RunCode = 0;

        static bool LDTR_1_Clamp_Stop = false;
        static bool LDTR_1_Clamp_HomeCondition = false;
        static bool LDTR_1_Clamp_MoveCondition = false;
        static bool LDTR_1_Clamp_Homing = false;
        static bool LDTR_1_Clamp_Runing = false;
        static int LDTR_1_Clamp_RunCode = 0;

        static bool LDTR_2_Clamp_Stop = false;
        static bool LDTR_2_Clamp_HomeCondition = false;
        static bool LDTR_2_Clamp_MoveCondition = false;
        static bool LDTR_2_Clamp_Homing = false;
        static bool LDTR_2_Clamp_Runing = false;
        static int LDTR_2_Clamp_RunCode = 0;

        static bool ULDTR_1_Clamp_Stop = false;
        static bool ULDTR_1_Clamp_HomeCondition = false;
        static bool ULDTR_1_Clamp_MoveCondition = false;
        static bool ULDTR_1_Clamp_Homing = false;
        static bool ULDTR_1_Clamp_Runing = false;
        static int ULDTR_1_Clamp_RunCode = 0;

        static bool ULDTR_2_Clamp_Stop = false;
        static bool ULDTR_2_Clamp_HomeCondition = false;
        static bool ULDTR_2_Clamp_MoveCondition = false;
        static bool ULDTR_2_Clamp_Homing = false;
        static bool ULDTR_2_Clamp_Runing = false;
        static int ULDTR_2_Clamp_RunCode = 0;
#endregion

    }
}
